Skip to content

ERR_INVALID_MODULE_SPECIFIER with dynamic import via jest-light-runner --runInBand #1747

@cjroebuck

Description

@cjroebuck

Search Terms

ERR_INVALID_MODULE_SPECIFIER
jest-light-runner
typescript esm

Expected Behavior

It should transpile and run the typescript file

Actual Behavior

ERR_INVALID_MODULE_SPECIFIER when running the command

Steps to reproduce the problem

See the repro below

npm run test gives TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "file:///path/to/ts-node-repros/src/tests/foo.ts"

npm run test:working runs the tests successfully

The only difference is the --runInBand option which is implemented like this in jest-light-runner:

nicolo-ribaudo/jest-light-runner@fb70325

I think it's something to do with dynamic import and perhaps the ts-node/esm loader is not being invoked in this case or something?

Minimal reproduction

https://github.com/cjroebuck/ts-node-repro

Specifications

ts-node v10.7.0
node v16.14.2
compiler v4.6.4
tsconfig.json, if you're using one:

{
    "extends": "ts-node/node16/tsconfig.json",
    "ts-node": {
        "swc": true
    },
    "compilerOptions": {
        "module": "ESNext"
    }
}
  • Operating system and version: mac os monterey 12.0.1 (Apple M1 Max)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions