question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" after upgrade to 9.0.3

See original GitHub issue

Prerequisites

  • 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) and mocha --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 and node 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
buesingcommented, Aug 20, 2021

Yeah, I’m sticking with version 1.1.0 of the slugify package for now. Thanks!

0reactions
juergbacommented, Aug 20, 2021

@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 guide: to read
  • I recommend option 3) and pin @sindresorhus/slugify: ^1.1.0 (version before pur ESM)
  • otherwise --loader=ts-node/esm: see this guide. --loader is an experimental Node option (alias of --experimental-loader) and ts-node/esm is experimental loader hook.
  • sindresorhus guide: Can I import ESM packages in my TypeScript project? => yes, but you need to convert your project to output ESM. Your target is ES5. Why?
  • sindresorhus guide:
    • 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.

Read more comments on GitHub >

github_iconTop 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 >

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