Skip to content
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.resolve no longer available in loaders >= v20 #49198

Closed
halfmatthalfcat opened this issue Aug 16, 2023 · 5 comments · Fixed by #49242
Closed

import.meta.resolve no longer available in loaders >= v20 #49198

halfmatthalfcat opened this issue Aug 16, 2023 · 5 comments · Fixed by #49242
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders

Comments

@halfmatthalfcat
Copy link

halfmatthalfcat commented Aug 16, 2023

Version

20.0.0

Platform

Darwin ....* 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

package.json

{
  "name": "import-meta-resolve-test",
  "type": "module"
}

loader.mjs

export function load(url, _, next) {
  console.log(import.meta.resolve);
  return next(url);
}

index.mjs

console.log("hello world");

node --experimental-import-meta-resolve --experimental-loader ./loader.mjs ./index.mjs

How often does it reproduce? Is there a required condition?

  • Must be on Node v20 or above
  • Reproduced every time

What is the expected behavior? Why is that the expected behavior?

console.log in loader should resolve import.meta.resolve

What do you see instead?

undefined is printed

Additional information

import.meta.resolve exists in <= Node v20, at least I checked in 16-19.

I didn't see anywhere in 20+ release notes of this capability being removed. If this is known, feel free to close this.

@halfmatthalfcat halfmatthalfcat changed the title import.meta.resolve no longer available in loaders import.meta.resolve no longer available in loaders >= v20 Aug 16, 2023
@halfmatthalfcat halfmatthalfcat changed the title import.meta.resolve no longer available in loaders >= v20 import.meta.resolve no longer available in loaders >= v20 Aug 16, 2023
@atlowChemi atlowChemi added esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders labels Aug 17, 2023
@atlowChemi
Copy link
Member

@nodejs/loaders cc

@aduh95
Copy link
Contributor

aduh95 commented Aug 17, 2023

Yes it's a known limitation, import.meta.resolve returns a string synchronously, however the resolve hook chain is async, so it can onl y be exposed on the main thread. We have considered to expose it on the loader thread but returning a promise instead of a string, but it was deemed too confusing so not worth it. We could consider expose a different utils that does the same thing but asynchronously.

@GeoffreyBooth
Copy link
Member

If it’s not documented yet then we should at least mention it in the docs, with any workarounds if there are any.

@aduh95
Copy link
Contributor

aduh95 commented Aug 17, 2023

Would you like to send a PR?

@GeoffreyBooth
Copy link
Member

Would you like to send a PR?

@aduh95 I don’t know who you’re addressing this to. I asked about possible workarounds in https://openjs-foundation.slack.com/archives/C053UCCP940/p1692289284713799.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants