Support for commonJS from npm for dev explicitly
See original GitHub issueDescribe the bug
I’m trying to use a dependency that does not use ES module https://unpkg.com/choices.js@9.0.1/public/assets/scripts/choices.js and while it works during the build it doesn’t work during the dev with the error
The requested module ‘/@modules/choices.js/public/assets/scripts/choices.js’ does not provide an export named ‘default’
I tried to use optimizeDeps
but it doesn’t work.
optimizeDeps: {
include: ['choices.js']
}
Reproduction
Install choices.js
and try to use it during development.
Suggestion / Idea
Is there an option to add commonjs to ES Module conversion for specific dependencies ? Something like :
commonJS: ['choices.js', 'dep2']
System Info
vite
version: 1.0.0-beta.11- Operating System: Linux
- Node version: 14.5.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Create a Hybrid NPM Module for ESM and CommonJS.
It supports a single source code base and creates a module that can be consumed by CommonJS and ESM apps and modules.
Read more >Explicit ESM in Node.js with .mjs - DEV Community
The straightforward answer to this is that having different file extensions allows you to be explicit in how you want to run your...
Read more >cjsc - npm
Utility that compiles CommonJS (NodeJS) modules into a single JavaScript file suitable for the browser. Latest version: 1.0.11, ...
Read more >How the module system, CommonJS & require works
Learn how the Node.js module system & CommonJS works and what does `require` do under the hood.
Read more >Compile a package that depends on ESM only library into a ...
npm uninstall typescript && npm install --save-dev typescript@next ... all envs which support Node cache modules, * but, just in case, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
h.js
has a valid single ESM file so it doesn’t need to be optimized/wrapped as ESM - it’s loaded directly as-is.m.js
is CJS and therefore is optimized into ESM and then resolved from optimized modules. So yes it is because of the package names.I tested this out with two other packages with “.js” in the name, h.js and m.js, with Vite during development.
👍
h.js
worked just fine. ❌m.js
gave the sameUncaught SyntaxError: The requested module '/@modules/m.js/m.js' does not provide an export named 'default'
error.Based on
h.js
working as expected, it seems the resolver can handle packages with.js
in the name just fine, and it comes down to how individual packages handle ESM compatibility (and how tools handle interopability)?