TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" after upgrade to 9.0.3
See original GitHub issuePrerequisites
- Checked that your issue hasn’t already been filed by cross-referencing issues with the
faq
label - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn’t just a feature that actually isn’t supported in the environment in question or a bug in your code.
- ‘Smoke tested’ the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.
Description
I just tried upgrading to 9.0.3 and i’m getting a TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts".
Running (obviously) on typescript, with the command
TS_NODE_PROJECT='./tsconfig.test.json' mocha -r ts-node/register -r tsconfig-paths/register 'src/**/*.test.ts'
.
This is my tsconfig.test.json:
{
"compilerOptions": {
"moduleResolution": "node",
"target": "es5",
"module": "commonjs",
"lib": ["es2015", "es2016", "es2017", "esnext", "dom"],
"strict": true,
"sourceMap": true,
"declaration": false,
"strictNullChecks": false,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"baseUrl": "src",
"paths": {
"@pages/*": ["pages/*"],
"@components/*": ["components/*"],
},
"typeRoots": ["node_modules/@types"]
},
"include": ["src"]
}
This used to work in 9.0.1
Steps to Reproduce
Run above code with the configuration on a .ts file using ES modules.
Expected behavior: The file is being loaded and executed
Actual behavior: An error is thrown
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts".
Reproduces how often: 100%
Versions
- The output of
mocha --version
andnode node_modules/.bin/mocha --version
: 9.0.2 - The output of
node --version
: v14.16.1 - Your operating system
- name and version: MacOS
- architecture (32 or 64-bit): 64bit
- Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Can't run my Node.js Typescript project TypeError ...
I just resorted to using tsc --outDir out file.ts and then running the file ... Type catch clause variables as 'unknown' instead of...
Read more >error: typeerror [err_unknown_file_extension]: unknown file ...
In order to fix this problem, you need to remove "type": "modules" from the packages.json file. Once this has been removed, your project...
Read more >Unknown file extension ".CMD" - Flow Community
1|web | TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.CMD” for C:\USERS\30407792\CODE\KITTY-ITEMS\NODE_MODULES.BIN\NPM.
Read more >Unknown file extension ".json" : r/vuejs - Reddit
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json". Hi, Developers! command: => cross-env NODE_ENV ...
Read more >Running .tsx from the command-line - Hexmen
Here's a starter index.tsx file I'm going to use to generate HTML from ... TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, I’m sticking with version 1.1.0 of the slugify package for now. Thanks!
@buesing Yes, with this topic you are stumbling into an experimental minefield. You will have to spend considerable amount of time to get into it, or to get out again. I can give you some tipps, then I will kindly lead you to the exit.
esm
package: hasn’t been updated for over two years (=abandonded) and is not supported in Mocha v9. Mocha supports Node’s native ESM support.@sindresorhus/slugify: ^1.1.0
(version before pur ESM)--loader=ts-node/esm
: see this guide.--loader
is an experimental Node option (alias of--experimental-loader
) andts-node/esm
is experimental loader hook.Can I import ESM packages in my TypeScript project? => yes, but you need to convert your project to output ESM.
Your target isES5
. Why?Use only full relative file paths for imports
You must use a .js extension in relative imports even though you're importing .ts files
Edit: or don’t update to Mocha v9, stay on v8.