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.

Compatibility with planned node.js native ESM import resolution

See original GitHub issue

It appears that the node.js plan for native ESM is that file extensions will be mandatory. This directly conflicts with current xo rules import/extensions and unicorn/import-index. I’m opening this ticket to start the discussion about how/when xo should deal with this.

It appears that import/extensions only applies to import statements and not require. If/when proposal-pkg-exports sees progress import/extensions may need to be updated. unicorn/import-index applies to both import and require, might need an option so it can be applied to require only if that is desired. Might also need/want a rule that forbids direct import of the package main source.

In one of my private projects that is targeting ESM I have the following xo.rules in my package.json:

	"import/extensions": [
		"error",
		"always",
		{
			"ignorePackages": true
		}
	],
	"unicorn/import-index": "off"

Personally I’m not a fan of this but I feel like the decision has already been made.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
make-github-pseudonymous-againcommented, Feb 19, 2021

Hello! Is there a tool that can be used to automatically patch existing codebases by resolving old node syntax and replace it with mandatory file extensions?

2reactions
fregantecommented, Apr 6, 2020

Ideally XO should automatically disable those rules on modules (i.e. type: "module" directories and .mjs files)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ECMAScript modules | Node.js v19.3.0 Documentation
Modules are defined using a variety of import and export statements. The following example of an ES module exports a function:
Read more >
What does it take to support Node.js ESM? – The Guild
I have worked on all The Guild's libraries and graphql-js to support ESM. Here is how you can do it too.
Read more >
Using ES modules in Node.js - LogRocket Blog
Learn about the state of ES modules in Node today, including concerns realted to transitioning from and interoperability with CommonJS.
Read more >
Using ES modules natively in Node.js - 2ality
Path resolution works slightly differently: ESM does not support NODE_PATH and require. · ES modules are always loaded asynchronously, which ...
Read more >
Native ES Modules in NodeJS: Status And Future Directions ...
dynamic import is currently implemented only from Node 10. Migrating Applications from CJS to ESM. The Rules of ESM Modules and The Rules...
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