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 on typescript files (broken TS support on node 22.14) #57756

Closed
fregante opened this issue Apr 5, 2025 · 4 comments

Comments

@fregante
Copy link

fregante commented Apr 5, 2025

Version

v22.14.0

Platform

Darwin 192.168.88.98 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

echo "import 'node:console'" > file.ts
node file.ts

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

Support is documented here https://nodejs.org/api/typescript.html#type-stripping

What do you see instead?

node:internal/modules/esm/get_format:219
  throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
        ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for ~/file.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:219:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:245:36)
    at defaultLoad (node:internal/modules/esm/load:120:22)
    at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:514:32)
    at async ModuleJob._link (node:internal/modules/esm/module_job:115:19) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Node.js v22.14.0

Additional information

Feels like I'm missing something. Why does this not work? This also fails

$ echo "console.log(1 as number)" > file.ts
$ node file.ts --experimental-strip-types

SyntaxError: missing ) after argument list

This fails regardless of tsconfig presence

@ljharb
Copy link
Member

ljharb commented Apr 5, 2025

Both of these examples run fine for me on node 23; i can reproduce the issue on 22.14 - so it might be a fixed bug that just hasn't been backported to 22 yet?

@fregante fregante changed the title ERR_UNKNOWN_FILE_EXTENSION if the file use import ERR_UNKNOWN_FILE_EXTENSION on typescript files (broken TS support on node 22.14) Apr 5, 2025
@aduh95
Copy link
Contributor

aduh95 commented Apr 5, 2025

Feels like I'm missing something. Why does this not work? This also fails

$ echo "console.log(1 as number)" > file.ts
$ node file.ts --experimental-strip-types

The order of args matter, you should get better results with node --experimental-strip-types file.ts

@aduh95
Copy link
Contributor

aduh95 commented Apr 5, 2025

Unflagging has not been backported to v22.14.0 (doc can be found at https://nodejs.org/docs/latest-v22.x/api/typescript.html#type-stripping), and AFAICT using the flag works well, so I'm going to go ahead and close this. Feel free to reopen/comment if I missed something.

@aduh95 aduh95 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2025
@pmarchini

This comment has been minimized.

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

4 participants