You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ERR_INVALID_MODULE_SPECIFIER with dynamic import via jest-light-runner --runInBand #1747
On Wed, May 11, 2022 at 6:54 AM cjroebuck ***@***.***> wrote:
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)
—
Reply to this email directly, view it on GitHub
<#1747>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OBX77MUI7PAI6T7IVLVJOGXTANCNFSM5VUQEUXA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
The first --loader=esmock keeps esmock happy, but I'm assuming just gets ignored by node, because if I switch the order of the --loader's then I'm back to the original error (ERR_INVALID_MODULE_SPECIFIER).
Very clever, I'm glad it's working. I expect things may change as soon as node releases support for chaining multiple loaders. They have already merged the PR, so I expect that will be available in the next node release. Then you'll be able to pass --loader multiple times, and node will take care of chaining them together.
Is this a bug in esmock? It should support NODE_OPTIONS. If you agree, I recommend opening an issue with them.
Given that this is not a bug report nor a feature request, but is rather a useful how-to guide, I'm going to convert it to a Discussion.
Activity
cspotcode commentedon May 11, 2022
cjroebuck commentedon May 11, 2022
Yes, it seems that esmock explicitly checks for --loader=esmock in argv, so it is not currently possible to use the
NODE_OPTIONSenv variable to enable esmock at the same time as ts-node/esm.I'm also using your multiloader package for this so thank you for that too :)
The way I got this working in the end, with esmock and ts-node/esm loaders, was to change the command from:
NODE_OPTIONS='--experimental-specifier-resolution=node --loader @cspotcode/multiloader/compose?esmock,ts-node/esm' node --loader=esmock node_modules/.bin/jest --watch --runInBand --testPathPattern __tests__/*to:
node --experimental-specifier-resolution=node --loader=esmock --loader @cspotcode/multiloader/compose?esmock,ts-node/esm node_modules/.bin/jest --watch --runInBand --testPathPattern __tests__/*The first --loader=esmock keeps esmock happy, but I'm assuming just gets ignored by node, because if I switch the order of the --loader's then I'm back to the original error (ERR_INVALID_MODULE_SPECIFIER).
cspotcode commentedon May 11, 2022
Very clever, I'm glad it's working. I expect things may change as soon as node releases support for chaining multiple loaders. They have already merged the PR, so I expect that will be available in the next node release. Then you'll be able to pass
--loadermultiple times, and node will take care of chaining them together.Is this a bug in esmock? It should support
NODE_OPTIONS. If you agree, I recommend opening an issue with them.Given that this is not a bug report nor a feature request, but is rather a useful how-to guide, I'm going to convert it to a Discussion.