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

node: prefix not stripped from added dependency specifier #10052

Open
klswn opened this issue Dec 13, 2024 · 0 comments
Open

node: prefix not stripped from added dependency specifier #10052

klswn opened this issue Dec 13, 2024 · 0 comments

Comments

@klswn
Copy link

klswn commented Dec 13, 2024

🐛 bug report

When importing a node: prefixed builtin, the JS transformer is stripping the prefix in the import statement but the specifier on the added dependency is not mutated. When the packager generates the runtime code, it's mapping the node:{{builtin}} string to the public asset id instead of just {{builtin}}, which throws a Uncaught Error: Cannot find module {{builtin}} runtime error.

🎛 Configuration (.babelrc, package.json, cli command)

Version: 2.13.2

Default configuration running parcel serve

🤔 Expected Behavior

The runtime code should reference the non-prefixed builtin specifier

😯 Current Behavior

The runtime code references the node: prefixed specifier (from the REPL example pasted below):

"51LRJ":[function(require,module,exports,__globalThis) {
  var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
  var _nodeUrl = require("url"); <-- node: prefix is stripped
  var _nodeUrlDefault = parcelHelpers.interopDefault(_nodeUrl);
  function getHost(u) {
      return (0, _nodeUrlDefault.default).parse(u).host;
  }
  let testUrl = "https://test.com";
  document.body.innerHTML = getHost(testUrl);
},{
"node:url":"erk9V", <-- node: prefix is not stripped. throws runtime error.
"@parcel/transformer-js/src/esmodule-helpers.js":"03iyH"
}

💁 Possible Solution

I believe we just need to strip the prefix in dependency_collector.rs before adding the dependency in the JS transformer. But I'm not sure if that has other implications that I'm unaware of. I'm happy to assist with a PR if that path makes sense.

🔦 Context

We've run into a few runtime errors in our application attempting to import node: packages.

💻 Code Sample

REPL Example

🌍 Your Environment

I'm able to replicate in the REPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant