Skip to content

ERR_UNKNOWN_FILE_EXTENSION on Node v20.0.0 #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
septs opened this issue Apr 20, 2023 · 148 comments
Closed

ERR_UNKNOWN_FILE_EXTENSION on Node v20.0.0 #1997

septs opened this issue Apr 20, 2023 · 148 comments

Comments

@septs
Copy link

septs commented Apr 20, 2023

Search Terms

Node, ERR_UNKNOWN_FILE_EXTENSION

Expected Behavior

Fix it

Actual Behavior

see Minimal reproduction

Steps to reproduce the problem

see Minimal reproduction

Minimal reproduction

$ cat example.ts
console.log('example')
$ cat tsconfig.json
{ "ts-node": { "esm": true } }
$ npx ts-node example.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/septs/Projects/example/example.ts
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:139:38)
    at defaultLoad (node:internal/modules/esm/load:83:20)
    at nextLoad (node:internal/modules/esm/hooks:781:28)
    at load (/Users/septs/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/dist/child/child-loader.js:19:122)
    at nextLoad (node:internal/modules/esm/hooks:781:28)
    at Hooks.load (node:internal/modules/esm/hooks:381:26)
    at handleMessage (node:internal/modules/esm/worker:153:24)
    at checkForMessages (node:internal/modules/esm/worker:102:28) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Specifications

  • ts-node version: 10.9.1

  • node version: 20.0.0

  • TypeScript version: 5.0

  • tsconfig.json:

    { "ts-node": { "esm": true } }
  • package.json:

    {}
  • Operating system and version: macOS 13.3.1

@septs
Copy link
Author

septs commented Apr 20, 2023

microsoft/TypeScript#53922


Edited by 11/18/2023

Use tsx replace ts-node?

Or use ts-node@beta?

more see https://github.com/privatenumber/tsx, #2077

@csvn
Copy link

csvn commented Apr 20, 2023

I have the same issue. I tried using --esm, { "esm": true } and --loader="ts-node/register", but got the ERR_UNKNOWN_FILE_EXTENSION no matter what I tried. Could not get ts-node to run on Node v20 with native ESM modules.

@Jack-Works
Copy link

FYI Node 20 has made a breaking change:

Custom ESM loader hooks run on dedicated thread
ESM hooks supplied via loaders (--experimental-loader=foo.mjs) now run in a dedicated thread, isolated from the main thread. This provides a separate scope for loaders and ensures no cross-contamination between loaders and application code.

https://nodejs.org/en/blog/release/v20.0.0

@RobinTail
Copy link

+1

The issue also appears when using the specially dedicated ESM runner

$ ts-node-esm file.ts

queengooborg added a commit to openwebdocs/mdn-bcd-collector that referenced this issue Apr 22, 2023
@neurolag
Copy link

I went forward and downgraded my node version to lts.
However, doing node --loader ts-node/esm {file} did work for me.

@wibed
Copy link

wibed commented Apr 23, 2023

i expirience the same issue on:

# node --version
v18.16.0

EDIT:
my bad, i misinterpreted the gravity of the situation. manually enforcing the loader like this.

{
  "start": "npm run clean && cross-env NODE_ENV=development NODE_OPTIONS=\"--loader=ts-node/esm --trace-warnings\" webpack serve --mode=development --config webpack.config.ts",
}

worked out.

example sourced from here:
webpack/webpack-cli#2458

@RandivCosta
Copy link

i expirience the same issue on: Node v20,
I tried: $ node --loader ts-node/esm ./path
It worked for me but getting this warnning:
ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time

@sywesk
Copy link

sywesk commented May 4, 2023

I'd like to add quickly that on windows (at least), doing node --loader ts-node/esm ./path works but with an insanely high CPU usage. Doing a quick npx tsc + node ./build/app.js works perfectly without the performance issue.

@RobinTail
Copy link

RobinTail commented May 6, 2023

Yes, node --no-warnings=ExperimentalWarning --loader ts-node/esm file.ts helps to bypass the issue until it's fixed.

@Aenigma
Copy link

Aenigma commented May 6, 2023

yeah, I recently upgraded to node 20 and started running with the --loader ts-node/esm parameter but noticed that my memory usage in my application had skyrocketed to 32G before it would die from OOM. I went chasing for a cause because I assumed it was due to a change I made, but downgrading to node 19 lowered memory usage down to around 500M again. I assume this is probably related to the CPU issues @sywesk had.

So I'd recommend people stay off Node 20 until this is fixed if you don't want to have unexpected issues in your runtime.

@bisubus
Copy link

bisubus commented Oct 29, 2024

@TopchetoEU tsx isn't a full replacement and doesn't have type checks, I'm a bit sceptical about their development model privatenumber/tsx#671 . Not even accepting contributions without a donation?

@felipecrs
Copy link

I still think tsimp is a better replacement.

@shinebayar-g
Copy link

shinebayar-g commented Oct 29, 2024

@TopchetoEU tsx isn't a full replacement and doesn't have type checks, I'm a bit sceptical about their development model privatenumber/tsx#671 . Not even accepting contributions without a donation?

lol this is gold. nodejs should stop recommending this.

@bennycode
Copy link

I still think tsimp is a better replacement.

Why do you think so? I ran into multiple issues when using it: tapjs/tsimp#26

@felipecrs
Copy link

Oh, because it typechecks using tsc. That's why.

@TopchetoEU
Copy link

TopchetoEU commented Oct 29, 2024

@TopchetoEU tsx isn't a full replacement and doesn't have type checks, I'm a bit sceptical about their development model privatenumber/tsx#671 . Not even accepting contributions without a donation?

good point, but at least it still works with ESM.

@ItsHarper
Copy link

tsimp is great in theory, but it's extremely buggy, and can produce non-obviously stale results from because of caching bugs. tsc --noEmit && tsx is the way for now.

@the94air
Copy link

the94air commented Nov 4, 2024

ts-watch seems not affected with these breaking changes in node 20. I haven't tested it with bigger projects yet.

dev-arrow added a commit to dev-arrow/ui that referenced this issue Nov 27, 2024
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
@bennycode
Copy link

I created a video summarizing how to run ts-node with ESM on Node 20+: https://www.youtube.com/watch?v=-7dNs1ggKRs

The tsx tool is the recommended alternative (mentioned by @blakeembrey in #2140).

@imawizrd
Copy link

imawizrd commented Nov 28, 2024

Showcase of the problem:

demo.mp4

Here's all the loaders webpack supports

[webpack-cli] Unable load '/repo/folder/webpack.config.ts'
[webpack-clil Unable to use specified module loaders for " .ts".
[webpack-clil Cannot find module 'ts-node/register' from '/repo/folder'
[webpack-cli] Cannot find module 'sucrase/register/ts' from '/repo/folder'
[webpack-clil Cannot find module '@babel/register' from '/repo/folder'
[webpack-cli] Cannot find module 'esbuild-register/dist/node' from /repo/folder'
[webpack-clil Cannot find module '@swc/register' from '/repo/folder'
[webpack-clil Please install one of them

Webpack will check them in that order, mind you. So even if you have sucrase installed for example you have to manually uninstall ts-node before webpack automatically picks sucrase as loader.

So I just did (I use Yarn package manager, if you use NPM translate these commands to their equivalent)

yarn remove ts-node

and then

yarn add -D sucrase

No more configuration is needed (I don't have "type": "module" option in package.json, if you have it you may need additional configuration) and I can run webpack --config ./webpack.config.ts without any flags or workarounds.

Another thing, if you do not have "type": "module" option in package.json, the Webpack loader compiles the typescript config to commonJS, so you must use __dirname and __filename instead of import.meta.url if you need it, but you probably already know that.

ts-node is a great project and it has served me well over the years, so I'm sorry to have to remove it from my project. Please give all the support you can give to ts-node if you value it as I do.

@wes992
Copy link

wes992 commented Dec 13, 2024

I created a video summarizing how to run ts-node with ESM on Node 20+: https://www.youtube.com/watch?v=-7dNs1ggKRs

The tsx tool is the recommended alternative (mentioned by @blakeembrey in #2140).

This worked for me. By far the best solution I have come across. :)

@felipecrs
Copy link

Well, if there's anything positive out of it, I hope it somehow incentivize people to try a better runtime like Deno or Bun.

@TopchetoEU
Copy link

Well, if there's anything positive out of it, I hope it somehow incentivize people to try a better runtime like Deno or Bun.

unfortunately, sometimes you don't get to pick your runtime, and you're forced to use NodeJS, despite your best wishes.

@dandv
Copy link

dandv commented Dec 14, 2024

I've switched to Deno, but there are still some rough edges, especially when it comes to testing:

  1. There are no IDEs with full test support. Neither WebStorm nor the VS Code Deno plugin support BDD tests.
  2. expect toMatchObject does not do a diff between the objects to show the mismatched keys (Jest does, but it comes with its own TypeScript problems)

Also, there's no interop with ESLint rules, and Deno's built-in linting is just not up to par with typescript-eslint.

@shinebayar-g
Copy link

shinebayar-g commented Dec 14, 2024

Deno is still buggy... Bun too... Those nasty bugs are so annoying to find out later in the production..
Ironically with native ESM support in NodeJS, ts-node may start work again lol.

@lexandera
Copy link

What has been working for me for a long time - and continues to work on node 22 - is the following:

node --experimental-specifier-resolution=node --loader ts-node/esm/transpile-only file.ts

Even though --experimental-specifier-resolution has been removed by nodejs it continues to work with ts-node because it appears to contain loader code copied from an older nodejs version (see the "ts-node/raw" dir) and this switch activates a code path that is capable of loading .ts files in ESM mode.

FelisDiligens added a commit to FelisDiligens/md-table-tools that referenced this issue Jan 6, 2025
ReachGz added a commit to ReachGz/spoty that referenced this issue Jan 16, 2025
elite-0000 added a commit to elite-0000/shadcn-ui-ui that referenced this issue Jan 25, 2025
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
base-buzz pushed a commit to base-buzz/ui that referenced this issue Mar 25, 2025
…hadcn-ui#1977)

This pull request resolves shadcn-ui#1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in shadcn-ui#1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on shadcn-ui#1937. That will not happen again.
jolierabideau added a commit to paranext/platform-bible-extensions that referenced this issue May 12, 2025
* Initial commit

* Added multi-extension template based on paranext-core/extensions

* Changed Paranext to Platform.Bible in various places, misc improvements

* Added warning about editing update merge commit history

* Ignored dist and release when formatting extension

* Moved Special features description to this repo for lower frequency of merge conflicts

* Moved a lot of git things to consts, made it easier to localize error messages, genericized license

* Removed debug log

* Fixed a couple things related to packaging extensions

* Added 'shared with' statements to various style files and brought them in sync

* Removed no-non-null-assertion as it is covered by no-type-assertion

* remove papi-components, update packages, add platform-bible-utils as external

* Fixed emotion package duplication

* Reworked explanation for package aliases. Also removed note about splitting into its own repo as this problem will not be solved as long as the package used is local

* npm updates (#7)

- also add Volta node version

* Add contributions folder for menus.json (#8)

* Added copying settings and project settings contribution files

* Fixed git problems with inconsistent error messages

* Fixed swc bindings not found error

* security update `@sillsdev/scripture` (#11)

- also update other npm packages

* Updated to node 20.11.1 LTS, replaced ts-node with tsx in the necessary places as a temporary fix for TypeStrong/ts-node#1997

* Fix cjs typo 'csj'

* update all npm packages (#14)

- except `typescript` and `@typescript-eslint/*`

* Fixed dts self-import, used npm workspaces to clear up package issues

* Updated package-lock.json

* Added localized string contribution doc

* Stop formatting extension package-lock.json

* Added find and replace description to manual add extension explanation

* Bump braces from 3.0.2 to 3.0.3 (#19)

Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](micromatch/braces@3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: added displayData.json file for localization

* docs: updated README regarding displayData

* update `@sillsdev/scripture` (#21)

- enable full serialization that can now include verse ranges, sequences, and segments.

* refactor: adjusted file structure for extension descriptions

* update `@sillsdev/scripture` (#23)

- fix .NET deserialization

* Bump webpack from 5.91.0 to 5.94.0 (#25)

Bumps [webpack](https://github.com/webpack/webpack) from 5.91.0 to 5.94.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.91.0...v5.94.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update dependencies (#26)

- `npm audit fix`
- also ran `npx update-browserslist-db@latest`

* Added tailwind to multi template

* Changed readme template info to be hideable, made build script print helpful instructions if there are no extensions to build

* Updated sass, moved printing instructions so it always runs

* Moved LIBRARY_TYPE to fix circular dependency

* update dependencies (#29)

- also fix stylelint to work with tailwind @ directives

* Reworded tailwind instructions because file has changed to .css

* provide for type checking (#24)

- Type checking doesn't happen at this level but within each contained extension.
- use `noImplicitReturns` instead of `consistent-return`
- improve types on error handling
- also fix `micromatch` vulnerability using `npm audit fix`
- also run `npx update-browserslist-db@latest`

* improve linting (#31)

- use the TS version of `class-methods-use-this` so we can ignore override methods.

* add missing format check (#32)

- let prettier format CSS & SCSS
- also `npm audit fix`

* ignore extension node modules in tailwind config to fix warning

* Make ignore pattern more generic

* update dependencies (#34)

- `npm audit fix`
- update minor and patch dependencies

* Added link where it was missing, changed license to use copyright symbol

* update dependencies (#36)

- `npm audit fix` for esbuild

* fix linting (#37)

- remove jest (no longer used)
- remove duplicated eslint rule

* Changed main file target so it understands built-in modules except crypto are not available

* Adjusted extension name guidance - lowerCamelCase and kebab-case

* PT-2390: Minor wording improvements to README

* PT-2390: Consolidated repetitive instructions.

Added a reference to paranext-extension-template

* Remove MUI

* Update .eslintrc.cjs from the extension-template repo (#42)

* PT-2390: Minor wording improvements to README. Capitalized Webpack when used as the proper name of the product.

* Set up auto-release workflow (#44)

* Added consistent return in bump-versions (#45)

* Small fixes to auto-release process (#46)

* PT-1886: Set up theme contributions, fixed raw file imports not working properly (#47)

Set up theme contributions, fixed raw file imports not working properly

* Squashed 'src/platform-lexical-tools/' content from commit 0aa7a68

git-subtree-dir: src/platform-lexical-tools
git-subtree-split: 0aa7a6864a193d907b9da85c6ca342c6155504cd

* Create platform lexical tools extension

* add basic info to display data and description md

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: TJ Couch <[email protected]>
Co-authored-by: tjcouch-sil <[email protected]>
Co-authored-by: Jolie Rabideau <[email protected]>
Co-authored-by: Ira Hopkinson <[email protected]>
Co-authored-by: Matt Lyons <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Danny Hammer <[email protected]>
Co-authored-by: Danny Hammer <[email protected]>
Co-authored-by: Jolie Rabideau <[email protected]>
Co-authored-by: tombogle <[email protected]>
Co-authored-by: Rolf Heij <[email protected]>
Co-authored-by: Rolf Heij <[email protected]>
@gofugui
Copy link

gofugui commented May 21, 2025

package.json add "type": "module",

DarkMage108 added a commit to DarkMage108/shadcn-chatbot-kit that referenced this issue May 27, 2025
…#1977)

This pull request resolves #1926 and prevents issues like it from happening in the future

## Rationale for this PR

This PR changes the TypeScript execution package for use in scripts like `build:registry` from `ts-node` to `tsx`. This is because `ts-node` has many difficult quirks to work through (and is slow). In addition, it also has a difficult to understand error for newcomers that *is* reproducible.

### The ts-node error

As shown in #1926, using `ts-node` (specifically in `build:registry`) results in this error: `Unknown file extension ".ts" for /ui/apps/www/scripts/build-registry.ts`. There are many issues in the `ts-node` repository documenting this problem:
* TypeStrong/ts-node/issues/1062
* TypeStrong/ts-node/issues/2033
* TypeStrong/ts-node/issues/1997

Switching the typescript-in-node system to `tsx`, which uses esbuild under the hood, resolves this error.

This PR shouldn't affect tests, representation, etc. and is merely a change of build tools. There is no urgent need to merge this.

I accidentally deleted the head repository on #1937. That will not happen again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests