-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught Error: Dynamic require of "xxx/main.scss" is not supported, when ESM package import commonjs module #5308
Comments
I try follow config , not work
|
have the problem been solved? I have the same problem |
🤔 I have the same problem in other project too.I think that error is caused by require,so I download the minimal project you provider,then change from require to import in |
|
so, does anyone have a final solution?many projects have the problem to me |
I have the same problem in my project. Does anyone have a final solution? |
I have the same problem, any one has soluttion? |
I have the same issue with imported package from node_modules.
|
I have the similar problem, but my dependency is umd file, has anyone solved it? |
Wait, found the solution, there's a plugin for Vite from originjs team. This worked for me while trying to implement https://www.npmjs.com/package/@originjs/vite-plugin-commonjs Install the plugin:
Add it to your vite config:
(Note, I don't think the babel option is needed, but I'm including it just so everyone knows my exact config). |
Thank you so much, man. It work for me. I was troubled by this problem for a long time until I read your comments. |
Solved my problem. God bless you man. |
superjose's solution worked for me when running the dev server, but failed when attempting to deploy my code. In my case I'm trying to use ts-morph in the browser, which I think only comes as a UMD package. But the package does a dynamic import of code-block-writer, which is available as both UMD and ESM, but the UMD module is what ends up being resolved. In my case I get the same "Dynamic require ... not supported" but for a piece of code that code-block-writer includes in it's distributed files called "comment_char.js". This isn't a node_module dependency, it's literally just another file in the code-block-writer package. If I change the esbuild options to include
like superjose suggests, the
This error happens even if I build in development mode. Instead I got lucky and was able to use the 'alias' feature of vite config to force code-block-writer to be imported using the ESM files, instead of the UMD files that were imported presumably because the package importing it was UMD (ts-morph). Now it's working on dev and build. This may not be an option if the deep dependency causing the problem does not have an ESM version, but since it's using the alias feature, you could make an ESM build of the dependency and then alias to your own version. |
@AustinGrey Would you be able to share the |
I cannot confirm because the repro is now 404, but I think #8459 fixed this issue too. |
Describe the bug
error log in browser console panel:
Uncaught Error: Dynamic require of "/Users/ligfee/Documents/code/self/vite.d/demo.d/vite-issue-dep-dep/node_modules/@alifd/next/lib/icon/main.scss" is not supported
code analysis:
App import @yangfee/dep-1-demo, this package is ESM
@yangfee/dep-1-demo import a commonjs module
Reproduction
minimal project(github)
System Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: