-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npx
invocation yields ERR_INVALID_MODULE_SPECIFIER
#1663
Comments
I think this path might be wrong: https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d#file-npx-js-L49 When I look at the log output you shared, these are some of the paths I see:
The first, This would explain why it cannot find |
Whoops, fixed the path and now I get: Note: You'll need to clear your |
npx
invocation yields ERR_MODULE_NOT_FOUND
npx
invocation yields ERR_INVALID_MODULE_SPECIFIER
Are you able to share the full error, including |
|
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. |
Same result by the looks of it:
|
I am seeing that the path may still be wrong. Instead of
it should be
|
Also, you might need to include the |
I figured it out. The problem is primarily: a) hello.ts file is ignoredWhen you run stuff via Since the file is ignored, it does not get special treatment by our ESM loader. Node's default behaviour is used, and node does not understand the Explained here: If you configure b) we can't automatically pick up your
|
Is it possible to pass options to the loader in the command? Like so?:
I couldn't really tell from the docs. Ideally I could set the |
It's not, because you're invoking node, not ts-node, so those flags all go
to node, and it'll throw an error that it does not understand them.
…On Tue, Mar 1, 2022, 2:53 PM Brian Jenkins ***@***.***> wrote:
Is it possible to pass options to the loader in the command? Like so?:
node --experimental-specifier-resolution=node --loader=ts-node/esm --skipIgnore hello.ts
^^^^^^^^^^^^
I couldn't really tell from the docs. Ideally I could set the --project
flag the same way.
—
Reply to this email directly, view it on GitHub
<#1663 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35ODRVT5XZ45V4DEEMNDU5ZYTFANCNFSM5PPQV52Q>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Huzzah, it works!
It doesn't print out "Hello, world!" for some reason but I can dig into that on my own. Thanks so much for your help, @cspotcode ! For the future reader, here's what worked: https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d#file-npx-js-L10-L53 |
Hmm, apparently it was just failing silently with an ENOENT, so I'm still seeing the issue and all the paths appear to be correct:
All resolve to the correct files. I set the const options = {
"cwd": process.cwd(),
"encoding": "utf8",
"env": {
+ "TS_NODE_PROJECT": path.join(directory, "tsconfig.json"), // https://github.com/TypeStrong/ts-node/pull/1655
+ "TS_NODE_SKIP_IGNORE": true
},
"stdio": "inherit"
}; So something still seems afoot. 🤔 Stacktrace (only visible from the debugger for some reason: |
Don't forget to spread all other environment variables: `...process.env`
…On Wed, Mar 2, 2022, 9:04 AM Brian Jenkins ***@***.***> wrote:
Hmm, apparently it was just failing silently with an ENOENT, so I'm still
seeing the issue and all the paths appear to be correct:
- ✅
/Users/bjenks/.npm/_npx/caa40e90fbe6bfad/node_modules/sampleThatReproducesTheIssue/tsconfig.json
- ✅
/Users/bjenks/.npm/_npx/caa40e90fbe6bfad/node_modules/ts-node/esm.mjs
- ✅
/Users/bjenks/.npm/_npx/caa40e90fbe6bfad/node_modules/sampleThatReproducesTheIssue/hello.ts
All resolve to the correct files.
I set the env property in the options for the workarounds needed for
ts-node:
const options = {
"cwd": process.cwd(),
"encoding": "utf8",
"env": {
+ "TS_NODE_PROJECT": path.join(directory, "tsconfig.json"), // #1655
+ "TS_NODE_SKIP_IGNORE": true
},
"stdio": "inherit"
};
So something still seems afoot. 🤔
Stacktrace (only visible from the debugger for some reason: npx
--node-options=--inspect-brk
https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d):
[image: Screen Shot 2022-03-02 at 9 04 03 AM]
<https://user-images.githubusercontent.com/9398474/156376612-f8a0afb0-71f1-4d62-bca6-50152c3edd56.png>
—
Reply to this email directly, view it on GitHub
<#1663 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35ODKSSHV6OPXQHIAJ4LU55YPHANCNFSM5PPQV52Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Ah, cool, I would not have come up with that. It works. Thanks again! |
This isn't conclusively anything yet, but there seems to be some issue with path concatenation on Windows:
It builds the (clearly invalid) path:
for some reason. Can't tell if it's something I'm doing or something And depending on whether or not I preface the file argument with
|
To double-check, are you using the absolute latest versions of |
My Windows box:
I'll upgrade node to v17.6.0. Different error on Windows (Node.js v17.6.0):
Copying and pasting what it was supposed to
Removing the leading
|
Thanks, would you mind copy-pasting this into a new issue? Seems like it's a new error, and this issue is closed, so would be easier to track it fresh and go from there. |
Yes, will do. |
(@cspotcode This is from a while back on Discord)
Search Terms
Context
I run my typescript (served via
npx
) throughts-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
Steps to reproduce the problem
Minimal reproduction
https://gist.github.com/brianjenkins94/d73578d7439427a59df28c1bc751e02d
Specifications
tsconfig.json
The text was updated successfully, but these errors were encountered: