-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
import.meta.url
is undefined when using stdin such as ... | node --input-type=module -
#38714
Comments
@nodejs/modules |
Is this marked as a bug or can it be closed as expected behaviour? Thank you! |
We should probably be pinging @nodejs/loaders from now on as most of the people from the old modules team have low bandwidth these days. I too have quite a bit on my plate atm, but let's see if anyone can triage first. Thanks for your patience! |
This isn't related to loaders, though - it's likely an oversight in the |
This actually was brought up in #36472 that we don't have a good URL to give these things. |
Thanks for the updates! Also no worries about low bandwidth - same here 😅 It'll happen when it happens. @bmeck do you mean it's not a good URL because it could conflict with the filesystem? I imagine people who were worried about the edgecase could stat the fs to check for the file if it starts with |
@heyheyhello I just mean that we haven't made a decision and consensus on what to call them; yes it can conflict with files and that is a bit troublesome but the bigger issue is if we give it a |
@bmeck what about a |
@zackschuster
So, while I think it would be somewhat simple, it is not very clean. We could also use a |
I worry that using an |
stdin isn't a location on the filesystem. i think using a |
neither |
Could the interim fix be to return |
@ilkkao @devsnek I know it's a "weird relative operation" but It feels more clear to place items to relative to eachother rather than relative to me (the directory my shell is parked in). Like saying "the bowls are in the cupboard above the cutlery drawer" instead of "the bowls are 45deg CW and 2 steps from you right now". It's possible that maybe both options are equally as fragile considering binaries and config files can (and do!) move around; moving webpack.config.js to webpack/base.config.js will break Edit: I also just remembered that using |
@heyheyhello right, I didn't read the description well enough. Just as an option, maybe root path |
I've made a PR for this |
What steps will reproduce the bug?
I write TypeScript which Node doesn't read so I write
esbuild thefile.ts | node --input-type=module -
to strip the TS typings and pass the ESM directly to Node. This works 💯👍However, if the code uses
import.meta.url
such asconst __dirname = path.dirname(fileURLToPath(import.meta.url));
this throws:Because
import.meta.url
is undefined. Shouldn't it be "file:///home/today/_/work/acorn-macros/test/style.macro/[eval1]" since that's what's shown in the stacktrace?How often does it reproduce? Is there a required condition?
Using
import.meta.url
when accepting a script via stdin.What is the expected behavior?
The
url
property is "file:///home/today/_/work/acorn-macros/test/style.macro/[eval1]"As a workaround you can hack this in via:
What do you see instead?
Throws :(
Additional information
Thank you for maintaining a wonderful project and doing all the work to make ESM in Node a success! ✨
The text was updated successfully, but these errors were encountered: