question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not get correct dependencies when mixing es6 and cjs import syntax

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

11reactions
mrjoelkempcommented, Oct 3, 2016

@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.

2reactions
mrjoelkempcommented, Oct 1, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found