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

not even the most simple use-case #2083

Open
AndreLeifert opened this issue Nov 3, 2023 · 3 comments
Open

not even the most simple use-case #2083

AndreLeifert opened this issue Nov 3, 2023 · 3 comments

Comments

@AndreLeifert
Copy link

sudo npm i -g ts-node typescript
ts-node -v
v10.9.1
echo 'console.log("OK")' > tst.ts
ts-node tst.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/andre/play/tic/bmos-ic/tst.ts
at new NodeError (node:internal/errors:405:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
at defaultGetFormat (node:internal/modules/esm/get_format:124:36)
at defaultLoad (node:internal/modules/esm/load:84:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:603:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

@Bjoren
Copy link

Bjoren commented Nov 13, 2023

Adding to this, I can't get ts-node to work at all with ESM.

A brand new project with a package.json:

{
  "type": "module",
  "dependencies": {
    "ts-node": "^10.9.1",
    "typescript": "^5.2.2"
  }
}

... and a tsconfig.json:

{
  "type": "module",
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
  },
  "ts-node": {"esm": true}
}

Refuses to run script.ts

console.log("Hello world")

... with TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for <path>\project\script.ts

Very non-descriptive error message.

@AndreLeifert
Copy link
Author

Yes, confirmed: like @Bjoren, I have "type": "module" in my package.json.
Also tried with --esm on the command line as well as with ts-node-esm... whatever that is.
Same result. Do we really have to add the suffix .js to all imports?

@wolfy1339
Copy link

Duplicate of #1997

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

3 participants