Skip to content

fix: unable to load CommonJS in vite plugin - #3204

Merged
marvinhagemeister merged 1 commit into
mainfrom
vite-plugin-commonjs
Aug 7, 2025
Merged

fix: unable to load CommonJS in vite plugin#3204
marvinhagemeister merged 1 commit into
mainfrom
vite-plugin-commonjs

Conversation

@marvinhagemeister

@marvinhagemeister marvinhagemeister commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

Vite has an internal check that limits CommonJS detection to only bare specifier. This doesn't work well together with us resolving npm modules to absolute file paths.

https://github.com/vitejs/vite/blob/main/packages/vite/src/node/ssr/fetchModule.ts#L46

I've tried re-using our own instance of @rollup/plugin-commonjs or esbuild but couldn't get these to work in that setup. The easiest way seems to be to just write our own CJS -> ESM translation layer.

With a little luck since the Deno ecosystem is heavy into ESM we might get away with this. In either way this removes one of the two blockers to using the vite plugin.

Vite has an internal check that limits CommonJS detection to only bare specifier. This doesn't work well together with us resolving npm modules to absolute file paths.

I've tried re-using our own instance of `@rollup/plugin-commonjs` or `esbuild` but couldn't get these to work in that setup. The easiest way seems to be to just write our own CJS -> ESM translation layer.

With a little luck since the Deno ecosystem is heavy into ESM we might get away with this. In either way this removes one of the two blockers to using the vite plugin.
@marvinhagemeister
marvinhagemeister merged commit a084a2c into main Aug 7, 2025
9 checks passed
@marvinhagemeister
marvinhagemeister deleted the vite-plugin-commonjs branch August 7, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant