Bug: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ""

See original GitHub issue

What is the current behavior?

Currently, even with a successful build using tsc the /bin/run command fails with the following error:

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

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for D:\Dokumente\GAWD\Programmierung\Web-Dev\TypeScript\Project\Kipper\kipper\bin\run
←[90m    at new NodeError (node:internal/errors:371:5)←[39m
←[90m    at Object.file: (node:internal/modules/esm/get_format:72:15)←[39m
←[90m    at defaultGetFormat (node:internal/modules/esm/get_format:85:38)←[39m
←[90m    at defaultLoad (node:internal/modules/esm/load:13:42)←[39m
←[90m    at ESMLoader.load (node:internal/modules/esm/loader:303:26)←[39m
←[90m    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:58)←[39m
←[90m    at new ModuleJob (node:internal/modules/esm/module_job:63:26)←[39m
←[90m    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:244:11)←[39m
    at async Promise.all (index 0)
←[90m    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)←[39m {
  code: ←[32m'ERR_UNKNOWN_FILE_EXTENSION'←[39m
}

To reproduce

  • Use node v16.13.0 on Windows 10.0.19043 Build 19043
  • Use oclif@1.18.1 with the default configuration
  • Run npx oclif multi <name> and select TS and none of the CI extensions
  • Answer yes to eslint
  • Answer yes to mocha
  • Run tsc to compile the source code
  • Run /bin/run and view error (for me)

package.json

{
  "name": "kipper",
  "description": "The Kipper programming language (CLI implementation)",
  "version": "0.0.2",
  "author": "Luna-Klatzer @Luna-Klatzer",
  "bin": {
    "kipper": "./bin/run"
  },
  "bugs": "https://github.com/Luna-Klatzer/kipper/issues",
  "devDependencies": {
    "@oclif/dev-cli": "^1.26.0",
    "@oclif/test": "^1.2.8",
    "@types/chai": "^4.2.22",
    "@types/mocha": "^5.2.7",
    "@types/node": "^10.17.60",
    "chai": "^4.3.4",
    "eslint": "^7.11.0",
    "eslint-config-oclif": "^3.1.0",
    "eslint-config-oclif-typescript": "^0.1.0",
    "globby": "^10.0.2",
    "mocha": "^5.2.0",
    "nyc": "^14.1.1",
    "rimraf": "^3.0.2",
    "ts-node": "^8.10.2",
    "typescript": "^3.9.10"
  },
  "engines": {
    "node": ">=12.0.0"
  },
  "files": [
    "/bin",
    "/lib",
    "/npm-shrinkwrap.json",
    "/oclif.manifest.json"
  ],
  "homepage": "https://github.com/Luna-Klatzer/kipper",
  "keywords": [
    "oclif"
  ],
  "license": "GPL-3.0",
  "main": "lib/index.js",
  "oclif": {
    "commands": "./lib/commands",
    "bin": "kipper",
    "plugins": [
      "@oclif/plugin-help"
    ]
  },
  "repository": "Luna-Klatzer/kipper",
  "scripts": {
    "postpack": "rimraf oclif.manifest.json",
    "posttest": "npm run tslint",
    "prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
    "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
    "version": "oclif-dev readme && git add README.md",
    "prebuild": "npm run tslint",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "rebuild": "npm run build",
    "lint": "npm run tslint && npm run prettier",
    "lint:fix": "npm run tslint:fix && npm run prettier",
    "prettier": "prettier --write ./src/",
    "tslint": "eslint src/**/*.ts --ext .ts --config .eslintrc",
    "tslint:fix": "eslint src/**/*.ts --fix --ext .ts --config .eslintrc && npm run prettier",
    "antlr4ts": "antlr4ts -visitor -o src/compiler/parser/ Kipper.g4"
  },
  "types": "lib/index.d.ts",
  "dependencies": {
    "@oclif/command": "^1.8.0",
    "@oclif/config": "^1.17.0",
    "@oclif/plugin-help": "^3.2.4",
    "tslib": "^1.14.1",
    "antlr4ts": "^0.5.0-alpha.4",
    "antlr4ts-cli": "^0.5.0-alpha.4"
  },
  "prettier": {
    "tabWidth": 2,
    "singleQuote": false
  },
  "type": "module"
}

I also was able to get this behaviour with the following configuration file that is in my stable project:

{
  "name": "kipper",
  "description": "The Kipper programming language (CLI implementation)",
  "version": "0.0.2",
  "author": "Luna-Klatzer @Luna-Klatzer",
  "bin": {
    "kipper": "./bin/run.cjs"
  },
  "dependencies": {
    "antlr4ts": "^0.5.0-alpha.4",
    "antlr4ts-cli": "^0.5.0-alpha.4",
    "@oclif/command": "^1.8.0",
    "@oclif/config": "^1.17.0",
    "@oclif/plugin-help": "^3.2.4",
    "tslib": "^1.14.1"
  },
  "devDependencies": {
    "@oclif/dev-cli": "^1.26.0",
    "@oclif/test": "^1.2.8",
    "@types/chai": "^4.2.22",
    "@types/mocha": "^9.0.0",
    "@typescript-eslint/eslint-plugin": "^5.3.1",
    "chai": "^4.3.4",
    "eslint": "^8.2.0",
    "eslint-plugin-unicorn": "^38.0.1",
    "eslint-config-oclif": "^4.0.0",
    "eslint-config-oclif-typescript": "^1.0.2",
    "globby": "^11.0.1",
    "mocha": "^8.2.1",
    "nyc": "^15.1.0",
    "rimraf": "^3.0.2",
    "typescript": "^4.4.3",
    "prettier": "^2.4.1",
    "@sinonjs/commons": "^1.8.3",
    "@sinonjs/eslint-config": "^4.0.4",
    "@sinonjs/fake-timers": "^8.1.0",
    "@types/sinonjs__fake-timers": "~6.0.0",
    "ts-node": "^9.0.0"
  },
  "engines": {
    "node": ">=12.0.0"
  },
  "files": [
    "/bin",
    "/lib",
    "/npm-shrinkwrap.json",
    "/oclif.manifest.json"
  ],
  "homepage": "https://github.com/Luna-Klatzer/Kipper",
  "bugs": "https://github.com/Luna-Klatzer/Kipper/issues",
  "repository": {
    "type": "git",
    "url": "https://github.com/Luna-Klatzer/Kipper"
  },
  "keywords": [
    "oclif",
    "language",
    "compiler",
    "cli",
    "C"
  ],
  "license": "GPL-3.0",
  "main": "lib/index.js",
  "oclif": {
    "commands": "./lib/commands",
    "bin": "kipper",
    "plugins": [
      "@oclif/plugin-help"
    ]
  },
  "scripts": {
    "postpack": "rimraf oclif.manifest.json",
    "posttest": "npm run lint:fix",
    "prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
    "test": "nyc --extension .ts mocha --forbid-only \"**/*.test.ts\"",
    "version": "oclif-dev readme && git add README.md",
    "prebuild": "npm run tslint",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "rebuild": "npm run build",
    "lint": "npm run tslint && npm run prettier",
    "lint:fix": "npm run tslint:fix && npm run prettier",
    "prettier": "prettier --write ./src/",
    "tslint": "eslint src/**/*.ts || true",
    "tslint:fix": "eslint src/**/*.ts --fix || true && npm run prettier",
    "antlr4ts": "antlr4ts -visitor -o src/compiler/parser/ Kipper.g4"
  },
  "types": "lib/index.d.ts",
  "prettier": {
    "tabWidth": 2,
    "singleQuote": false
  },
  "type": "module"
}

What is the expected behaviour?

The CLI should run without problems and execute properly.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
fed-grencommented, Nov 24, 2021

I have the same issue. developing node using typescript, I know that need "type": "module" in package.json to use import/export. But when I remove "type": "module" it works fine. Why?

3reactions
marckrawcommented, Jan 24, 2022

@fed-gren Exactly, does Oclif support native esm ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't run my Node.js Typescript project TypeError ...
Can't run my Node.js Typescript project TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts · Ask Question.
Read more >
Error: unknown file extension .ts · Issue #1062 - GitHub
When I try to execute a typescript file I get the following error message: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ...
Read more >
unknown file extension .tsx - You.com | The AI Search Engine ...
Hi all, When I try to use .ts files with piscina I get an error. TypeError [ERRUNKNOWNFILE_EXTENSION]: Unknown file extension ".ts" Please explain...
Read more >
Unknown file extension ".ts" with mocha-node.js - appsloveworld
[Solved]-TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" with mocha-node.js. Search. score:0. Must be a problem with ESM support ...
Read more >
Express兼容ES6-import报错:TypeError ... - CSDN博客
获取错误TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file ... /getting-error-typeerror-err-unknown-file-extension-unknown-file-extension.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found