Skip to content
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

ERR_UNKNOWN_FILE_EXTENSION since Node.js 18.19.0 (works fine with 18.18.2) #2094

Open
mlenkeit opened this issue Dec 1, 2023 · 17 comments
Open

Comments

@mlenkeit
Copy link

mlenkeit commented Dec 1, 2023

Search Terms

  • ERR_UNKNOWN_FILE_EXTENSION
  • Node.js 18.19.0
  • Node.js 18.18.2

Expected Behavior

npx ts-node <script.ts> works on Node.js 18.19.0 just as it does with 18.18.2.

Actual Behavior

Since the upgrade to Node.js 18.19.0, the call fails with ERR_UNKNOWN_FILE_EXTENSION.

All other potentially related parameters remained unchanged (e.g. package-lock.json, ts-config.json, etc.).

We discovered this with GitHub workflow runs that run periodically (with schedule) at short intervals; only difference since things started failing is the Node.js version.

Steps to reproduce the problem

  • set up Node.js 18.19.2
  • set "type": "module" in package.json
  • set "esm": true in tsconfig.json
  • create main.ts with something like: console.log('Hello world')
  • run npx ts-node main.ts

Minimal reproduction

see https://github.com/mlenkeit/ts-node-repro

there's also a GitHub workflow to run this repo against Node.js 18.19.0 and 18.18.2:
https://github.com/mlenkeit/ts-node-repro/actions/runs/7057725777

Specifications

  • ts-node version: v10.9.1
  • node version: v18.19.0
  • TypeScript version: v5.2.2
  • tsconfig.json, if you're using one:
    {
      "extends": "@tsconfig/node18/tsconfig.json",
      "ts-node": {
        "esm": true
      },
      "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "moduleResolution": "Node",
        "module": "ESNext",
        "noImplicitAny": false,
        "strictNullChecks": true,
        "sourceMap": true,
        "outDir": "./dist",
        "resolveJsonModule": false,
        "types": [
          "node"
        ]
      },
      "exclude": ["node_modules"]
    }
    
  • package.json:
    {
      "name": "ts-node-repro",
      "private": true,
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "type": "module",
      "dependencies": {
        "@tsconfig/node18": "18.2.2",
        "@types/node": "18.16.1",
        "ts-node": "10.9.1",
        "typescript": "5.2.2"
      }
    }
    
  • Operating system and version: macOS Sonoma 14.1.1
@michael42
Copy link

Workaround: You can use node --loader ts-node/esm file.ts instead of ts-node --esm file.ts (which causes a ExperimentalWarning: --experimental-loader may be removed in the future). It would be great if ts-node provided an entrypoint that calls register from node:module, which seems to be Node's preferred way of registering loaders, now.

@mlenkeit
Copy link
Author

mlenkeit commented Dec 1, 2023

@michael42 thanks for the suggestion. This indeed works with both Node.js 18.18.2 and 18.19.0.

I will, however, hold back with applying that change for now, as this would require changes across a dozen or so repos. We've simply pinned Node.js to 18.18.2 for now to unblock us.

I still consider this to be a bug in ts-node.

@jetwiwo
Copy link

jetwiwo commented Dec 4, 2023

Same issue in node v20.10.0 (current LTS)

@JonWallsten
Copy link

Workaround: You can use node --loader ts-node/esm file.ts instead of ts-node --esm file.ts (which causes a ExperimentalWarning: --experimental-loader may be removed in the future). It would be great if ts-node provided an entrypoint that calls register from node:module, which seems to be Node's preferred way of registering loaders, now.

This does not seem to work for me:
node --loader ts-node/esm -r tsconfig-paths/register ./scripts/deploy.ts

(node:129) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
/builds/ci-vct-dev/aws-platform-ci/aws-cdk/scripts/deploy.ts:1
import { AWS_DOMAIN } from '../shared-lib/src/environment/compile';
^^^^^^

spalladino added a commit to AztecProtocol/aztec-packages that referenced this issue Dec 5, 2023
We were using a floating version of node in our base images, which means
we didn't control when we updated the node version. Also, we were using
an outdated version for local development, which didn't match the one
used for the base images.

This changeset bumps nvmrc to latest node (18.19.0) and pins down the
version of all node base images across dockerfiles in the project.

This PR was triggered by suddenly hitting [this
error](TypeStrong/ts-node#2094) in CI.
@jetwiwo
Copy link

jetwiwo commented Dec 5, 2023

Workaround: You can use node --loader ts-node/esm file.ts instead of ts-node --esm file.ts (which causes a ExperimentalWarning: --experimental-loader may be removed in the future). It would be great if ts-node provided an entrypoint that calls register from node:module, which seems to be Node's preferred way of registering loaders, now.

This does not seem to work for me: node --loader ts-node/esm -r tsconfig-paths/register ./scripts/deploy.ts

(node:129) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
/builds/ci-vct-dev/aws-platform-ci/aws-cdk/scripts/deploy.ts:1
import { AWS_DOMAIN } from '../shared-lib/src/environment/compile';
^^^^^^

Make sure you have "type": "module" in package.json or rename the file to file.mts

AztecBot pushed a commit to AztecProtocol/barretenberg that referenced this issue Dec 6, 2023
We were using a floating version of node in our base images, which means
we didn't control when we updated the node version. Also, we were using
an outdated version for local development, which didn't match the one
used for the base images.

This changeset bumps nvmrc to latest node (18.19.0) and pins down the
version of all node base images across dockerfiles in the project.

This PR was triggered by suddenly hitting [this
error](TypeStrong/ts-node#2094) in CI.
@mlenkeit
Copy link
Author

mlenkeit commented Dec 7, 2023

Same issue in node v20.10.0 (current LTS)

@jetwiwo right, thanks for mentioning that. FWIW, it looks like it doesn't work with Node.js 20 at all. I've added Node.js 20 versions to the repo for reproducing the problem.

image

https://github.com/mlenkeit/ts-node-repro/actions/runs/7125070507

Brooooooklyn added a commit to toeverything/AFFiNE that referenced this issue Dec 7, 2023
p2004a added a commit to p2004a/maps-metadata that referenced this issue Dec 7, 2023
There is issue with node 18.19 and also newer version breaking
ts-node: TypeStrong/ts-node#2094. This
is a quick fix until finding a more proper solution.
p2004a added a commit to beyond-all-reason/maps-metadata that referenced this issue Dec 7, 2023
There is issue with node 18.19 and also newer version breaking ts-node:
TypeStrong/ts-node#2094. This is a quick fix
until finding a more proper solution.
larabr added a commit to openpgpjs/openpgpjs that referenced this issue Dec 8, 2023
This fix triggers some warnings about experimental features,
and it's meant to be temporary until ts-node shares a long-term solutio .

See TypeStrong/ts-node#2094.
larabr added a commit to ProtonMail/openpgpjs that referenced this issue Dec 8, 2023
This fix triggers some warnings about experimental features,
and it's meant to be temporary until ts-node shares a long-term solutio .

See TypeStrong/ts-node#2094.
@ajvincent
Copy link

See #1997 - this sounds like a duplicate of that one.

giseburt added a commit to 10mi2/tms-projen-projects that referenced this issue Feb 23, 2024
Workaround `ts-node` bug with Node 18.19 and newer, where running `ts-node` with `esm` support enabled will fail with the error `ERR_UNKNOWN_FILE_EXTENSION` when you run `projen` itself.

Tracking: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update the ng-dev configuration to be compatible with Node.js 18.16. This adjustment eliminates the necessity for ts-node, which is crucial due to compatibility issues between the current tsnode esm version and the latest ESM loaders. For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update the ng-dev configuration to be compatible with Node.js 18.16. This adjustment eliminates the necessity for ts-node, which is crucial due to compatibility issues between the current tsnode esm version and the latest ESM loaders. For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update the ng-dev configuration to be compatible with Node.js 18.16. This adjustment eliminates the necessity for ts-node, which is crucial due to compatibility issues between the current tsnode esm version and the latest ESM loaders. For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update the ng-dev configuration to be compatible with Node.js 18.16. This adjustment eliminates the necessity for ts-node, which is crucial due to compatibility issues between the current tsnode esm version and the latest ESM loaders. For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 11, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 12, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to angular/angular-cli that referenced this issue Mar 12, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 15, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 15, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to angular/angular-cli that referenced this issue Mar 15, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
alan-agius4 added a commit to angular/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
clydin pushed a commit to angular/angular-cli that referenced this issue Mar 22, 2024
Update ng-dev setup to work with 18.19 For more details, refer to: TypeStrong/ts-node#2094

(cherry picked from commit a6129a6)
@sovietspaceship
Copy link

Any update on this? This has rendered ts-node completely unusable and not fit for purpose. The node --loader ts-node/esm file.ts and similar workarounds do not always work, and break all existing projects that now have to temporarily implement the workaround while this gets fixed.

@qiulang
Copy link

qiulang commented Apr 28, 2024

The other workaround is to use tsx instead. tsx also comes with watch mode, which is a bonus.

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