Skip to content

Possible regression with ts-node 10.0.0: ts extension not registered? #1368

Closed

Description

@jayaddison

Expected Behavior

For this codebase, running make tests (essentially, npx mocha) runs unit tests over some TypeScript code, and completes successfully. The codebase has ts-node configured matching semver ^9.1.1.

After upgrading the package.json ts-node entry to 10.0.0 in package.json file, and running npm install --also=dev, unit tests should continue to pass.

Actual Behavior

After the upgrade, unit tests fail:

TS_NODE_IGNORE='node_modules/(?!document-prev)' npx mocha

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/jka/Documents/reciperadar/document/src/index.spec.ts
    at new NodeError (node:internal/errors:363:5)
    at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)
    at Loader.getFormat (node:internal/modules/esm/loader:105:42)
    at Loader.getModuleJob (node:internal/modules/esm/loader:243:31)
    at Loader.import (node:internal/modules/esm/loader:177:17)
    at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at formattedImport (/home/jka/Documents/reciperadar/document/node_modules/mocha/lib/esm-utils.js:7:14)
    at Object.exports.loadFilesAsync (/home/jka/Documents/reciperadar/document/node_modules/mocha/lib/esm-utils.js:55:20)
    at singleRun (/home/jka/Documents/reciperadar/document/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/home/jka/Documents/reciperadar/document/node_modules/mocha/lib/cli/run.js:362:5)
make: *** [Makefile:9: tests] Error 1

Steps to reproduce the problem

Update the devDependency entry for ts-node, reinstall dependencies (including dev), and then run make tests.

Minimal reproduction

I'll attempt to narrow this down and fill in the minimal repro case soon.

Specifications

  • ts-node version: 10.0.0
  • node version: v16.1.0.
  • TypeScript version: v4.3.2
  • tsconfig.json, if you're using one:
{
    "compilerOptions": {
        "resolveJsonModule": true,
        "target": "ES5"
    }
}
  • Operating system and version: Manjaro Linux

Activity

  1. cspotcode commented on Jun 6, 2021

    @cspotcode
    Collaborator

    Not a regression, it's an improvement in our behavior to more closely align with nodejs, which is forcing you to use our ESM loader when your project uses "type": "module".

    Here is the relevant changelog entry:

    See also: #1342 which is pending feedback from some other open-source maintainers.

    Solutions for you in the short-term. You will have to decide which of these are viable:

    I believe that covers all the bases. If you need anything else, I recommend either the TypeScript Community Discord or our discussion forum. Both are linked from the navigation bar of our website: https://typestrong.org/ts-node

  2. jayaddison commented on Jun 6, 2021

    @jayaddison
    ContributorAuthor

    Thanks @cspotcode - and my apologies, I did read the changelog but I didn't catch that entry somehow. I think we can close this.

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

Metadata

Metadata

Assignees

No one assigned

    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