Skip to content

ts-node/register not supported in 9.0.0 #4665

Closed
@danielgindi

Description

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

mocha configuration contains require: ['ts-node/register'], in order to load the TS loader.
But since node_modules/ts-node/register is a folder, the new ESM loader in mocha fails to load, and throws:
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '...../node_modules/ts-node/register' is not supported resolving ES modules imported from ...../node_modules/mocha/lib/esm-utils.js

Steps to Reproduce

  1. npm i --save-dev ts-node
  2. Add require: ['ts-node/register'] to the .mocharc.yml

Expected behavior: Should work, and at least automatically resolve some well-known loaders like ts-node.

Actual behavior: Fails miserably.

Reproduces how often: 100%

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 9.0.0
  • The output of node --version: v15.12.0
  • Your operating system
    • name and version: MacOS 11.12.3
    • architecture (32 or 64-bit): M1
  • Your shell (e.g., bash, zsh, PowerShell, cmd): bash
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): ts-node 9.1.1

Activity

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

Metadata

Metadata

Assignees

Labels

area: node.jscommand-line-or-Node.js-specifictype: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions