`npx` invocation yields `ERR_INVALID_MODULE_SPECIFIER `
See original GitHub issue(@cspotcode This is from a while back on Discord)
Search Terms
- npx
Context
I run my typescript (served via npx
) through ts-node
so I don’t have to maintain a build.
For an example of how I had this working pre-ESM, see this gist.
Expected Behavior
The program runs without error. In the case of the linked gist, it runs hello.ts
, printing “Hello, world!”.
Actual Behavior
$ npx https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d
Need to install the following packages:
gist:d73578d7439427a59df28c1bc751e02d
Ok to proceed? (y) y
> node --experimental-specifier-resolution=node --loader=/Users/bjenkins/.npm/_npx/caa40e90fbe6bfad/ts-node/esm /Users/bjenkins/.npm/_npx/caa40e90fbe6bfad/node_modules/sampleThatReproducesTheIssue/hello.ts
(node:35543) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/bjenkins/.npm/_npx/caa40e90fbe6bfad/ts-node/esm' imported from /Users/bjenkins/Desktop/foo/
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:405:11)
at moduleResolve (node:internal/modules/esm/resolve:932:10)
at defaultResolve (node:internal/modules/esm/resolve:1044:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
at ESMLoader.import (node:internal/modules/esm/loader:276:22)
at initializeLoader (node:internal/process/esm_loader:74:49)
at loadESM (node:internal/process/esm_loader:87:11)
at runMainESM (node:internal/modules/run_main:47:21) {
code: 'ERR_MODULE_NOT_FOUND'
}
Steps to reproduce the problem
npx https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d
Minimal reproduction
https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d
Specifications
- ts-node version: v10.4.0
- node version: v16.13.2
- TypeScript version: v4.5.4
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": false,
"incremental": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "ESNext",
"moduleResolution": "Node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": false,
"alwaysStrict": true,
//"exactOptionalPropertyTypes": true,
//"strictNullChecks": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
//"strictPropertyInitialization": true,
//"noImplicitAny": true,
//"noImplicitThis": true,
//"useUnknownInCatchVariables": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"target": "ES2020"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"scripts/prev.ts"
]
}
- Operating system and version: macOS Monterey 12.1 (21C52)
Issue Analytics
- State:
- Created 2 years ago
- Comments:20
Top Results From Across the Web
"Failed to resolve module specifier "vue"" - Stack Overflow
I get the following error in the browser console: Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start ...
Read more >Errors | Node.js v19.3.0 Documentation
AssertionError s are a special class of error that can be triggered when Node.js detects an exceptional logic violation that should never occur....
Read more >package.json - npm Docs
In npm versions 3 through 6, peerDependencies were not automatically installed, and would raise a warning if an invalid version of the peer...
Read more >ES2020: `import()` – dynamically importing ES modules - 2ality
First, this import declaration can only appear at the top level of a module. That prevents you from importing modules inside an if...
Read more >The JavaScript Modules Handbook – Complete Guide to ES ...
CORS policy error in the browser's console - Modules Tutorial ... "Module specifier" and the "import specifier" are other names people call ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, I can take a closer look tonight. In the interim, I see that you’re using ts-node 10.4.0. It may be worth confirming that 10.5.0 exhibits the same behavior.
Yes, will do.