ESM should require file extensions
See original GitHub issue🐛 Bug Report
import t from './file';
import d from './directory/'
These should both fail to resolve, but since we use the same resolver as for CJS, it doesn’t, and the import will work while it would have failed at runtime. This is also the case for dynamic imports.
This might need some support in resolve
whenever they add support for ESM? https://github.com/browserify/resolve/issues/222
Place where we call resolve in jest: https://github.com/facebook/jest/blob/c024dec130d9914dcc3418ea74c26f667db3dbfa/packages/jest-runtime/src/index.ts#L395-L398 https://github.com/facebook/jest/blob/c024dec130d9914dcc3418ea74c26f667db3dbfa/packages/jest-runtime/src/index.ts#L423
Node docs: https://nodejs.org/api/esm.html#esm_mandatory_file_extensions Node issue for better errors: https://github.com/nodejs/node/issues/30603
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Explicit ESM in Node.js with .mjs - DEV Community
The Quick Answer. The straightforward answer to this is that having different file extensions allows you to be explicit in how you want...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Mandatory file extensions# A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes (e.g. ......
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
In turn, TypeScript supports two new source file extensions: .mts and .cts . ... You can read more about ESM/CommonJS interop in Node.js...
Read more >Why is Javascript module with ".js" file extension not found on ...
In ES Modules, file extension is mandatory, so you cannot omit the .js file extension like you can in CommonJS.
Read more >tsc-esm-fix - npm
Moreover, if understand TS/49271 correctly, nodenext + pkg.json type: module requires the .js extension in .d.ts files of external ESM ...
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
--experimental-specifier-resolution=node
is the flag. And yeah, we’d need to keep the logic around for that case… Not sure how to best detect if it has been passed. It’s not present inprocess.argv
so we might need to have our own option for this 🙁Bundlers are effectively a runtime target. I simply mean that, in terms of the TS team’s decision-making, it is technically valid ESM, which is why they’re supporting it. It’s not merely a backwards-compat issue. A lot of the ecosystem’s problems tend to get blamed on TS, when it’s actually TS playing along with the ecosystem’s desire to be custom at every turn.