vite-plugin-commonjs: Fail on cjs files in a node_modules folder somewhere out of the project
Hi, first of all, a really nice job!
I just came across an issue when I have to import a cjs file in another node_modules folder out of the target project. The error message is like:
caught SyntaxError: The requested module '/@fs/Users/jinjiang/xxx/packages/bar/node_modules/foo/index.js?v=f73c5dad' does not provide an export named 'foo' (at main.js?t=1682654369388:8:10)
The minimized reproduction is here to refer to: https://github.com/Jinjiang/reproductions/tree/vite-plugin-commonjs-20230428
As it mentions in the main.js:
// // this would work
// import { foo } from './foo'
// // this would work
// import { foo } from '../foo'
// this would fail
import { foo } from '../bar/node_modules/foo'
Thanks.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- refactor: better support `node_modules` #23 — committed to vite-plugin/vite-plugin-commonjs by caoxiemeihao 4 years ago
Update: I debugged a little bit and found this case hit 2 walls at the same time:
/node_modules/which might be skipped byfilterpath.extnameis only for file systems which can’t handle the query string likexxx.js?v=f73c5dad)However, I don’t have a big picture of your tech design yet. Not sure which way to solve this is the best and won’t involve other issues. So I’d like to leave the eventual bugfix to you.
Thanks.
It works now. Thanks.
Understood. It worked after I added the config. Thanks.
Would you mind checking one more case that I found? It’s about package
regexpu-core. If we haveimport rewritePattern from '../other-project/node_modules/regexpu-core', it will get this error:However,
import rewritePattern from 'regexpu-core'has no such a problem.This is also about requests to other node_modules. So I just put it in this same GitHub issue.
Thanks.