Does not get correct dependencies when mixing es6 and cjs import syntax
See original GitHub issueI’m working on a rather large code base that is slowly transitioning from es5 to es6. There are a lot of files that have mixed imports: i.e. both require()
statements and import
statements. node-precinct
does not correctly extract all the dependencies.
For example, given the file:
require('./foo');
import './bar';
only the foo
dependency will be recognized.
If you flip it around, and have a file like:
import './bar';
require('./foo');
only the bar
dependency will be recognized.
So in otherwords, precinct use looks at the first syntax it encounters and uses that for the rest of the file, even though the file may have a mix of cjs and es6.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9
Top Results From Across the Web
Discourage mixing CJS and ES6 module syntax in docs #552
Discourage mixing CJS and ES6 module syntax in docs #552 ... However, the getting started guide is importing it using the ES6 module...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
ESM scripts can import CJS scripts, but only by using the “default import” ... There would be no clear interop story for CommonJS...
Read more >How to Create a Hybrid NPM Module for ESM and CommonJS.
Author your code in ES6, ES-Next or Typescript using import and export. From this base, you can import either ES modules or CommonJS...
Read more >JavaScript Require vs. Import - Bits and Pieces
With modern web development, we use require or import to refer to JavaScript dependencies. And, sometimes, we use both in combination and ...
Read more >Why is 'type: module' in package.json file? - Stack Overflow
When you have "type": "module" in the package.json file, your source code should use import syntax. When you do not have, you should...
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
@pcardune I added an option
es6.mixedImports
that will chain the es6 and cjs detectives. See the usage docs for the syntax.You can get this with a fresh install of madge, but I’ll still bump precinct within dependency-tree.
Thanks again for suggesting the feature. Let me know if you run into any issues.
Fair point @pcardune! The goal of precinct is zero configuration, but i like the opt-in perf regression for transitionary codebases. Will work on that and support the option all the way up to madge.