set "type": "module" in `package.json` breaks the build
See original GitHub issueIt’ll get this error if you set the “type”: “module” in the package.json
node -r esbuild-register scripts/test.ts
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /scripts/test.ts
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
at Loader.getFormat (internal/modules/esm/loader.js:101:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:230:31)
at Loader.import (internal/modules/esm/loader.js:164:17)
at Object.loadESM (internal/process/esm_loader.js:68:5) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:24
- Comments:10 (5 by maintainers)
Top Results From Across the Web
setting "type" to "module" in package.json then not able to ...
I resolved it adding a package.json in the server folder scope with { "type": "module" } and removing that property from the main ......
Read more >Modules: Packages | Node.js v19.3.0 Documentation
Files with a .js extension when the nearest parent package.json file contains a top-level "type" field with a value of "module" .
Read more >Creating Node.js modules - npm Docs
Node.js modules are a type of package that can be published to npm. ... To create a package.json file, on the command line,...
Read more >How we employed the new ECMAScript Module Support in ...
js are loaded as ES modules when the nearest parent package.json file contains a top-level field “type” with a value of “module”. If...
Read more >Documentation - TypeScript 4.7
type in package.json and New Extensions. Node.js supports a new setting in package.json called type . "type" can be set to either "module"...
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
Thanks to @Savid 's comment, this was added in 3.4.0 : https://github.com/egoist/esbuild-register#experimental-loader-support
I’ve just been playing with ES modules recently and I’ve had some success with the suggestion from @danny-andrews;
esbuild-register-loader.mjs
then run;