Skip to content

npm package has "engines": ">=16.2.0" but npx tsc fails on node <20Β #64596

Description

πŸ”Ž Search Terms

node 18 ERR_UNKNOWN_FILE_EXTENSION

πŸ•— Version & Regression Information

  • ^7.0.2 in package.json, which installs 7.0.2

I didn't test this on prior versions because the way that Typescript starts changed with 7.

⏯ Playground Link

No response

πŸ’» Code

Create a new folder, then create the below package.json.
Switch to node 16 or 18 with nvm or something similar.

$ nvm use v18
$ npm install
$ npx tsc
{
  "name": "tsbug",
  "version": "1.0.0",
  "description": "",
  "engines": "16",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "type": "commonjs",
  "devDependencies": {
    "typescript": "^7.0.2"
  }
}

πŸ™ Actual behavior

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /home/nathan/dmp/tsbug/node_modules/typescript/bin/tsc. Loading extensionless files is not supported inside of "type":"module" package.json contexts. The package.json file /home/nathan/dmp/tsbug/node_modules/typescript/package.json caused this "type":"module" context. Try changing /home/nathan/dmp/tsbug/node_modules/typescript/bin/tsc to have a file extension. Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"tsc":"./bin/tsc.js"}}
    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 #createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

πŸ™‚ Expected behavior

the typescript help output.

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions