You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running into an issue where Parcel's JavaScript transformer is replacing require in output bundles in ways that is causing a runtime error.
It looks like this might be intentional behavior (#6260) that was added for compatibility with Browserify but it seems like it's maybe not working properly in this case.
This is causing an issue in one of our applications that has a dependency on dagre-d3, which basically structure all of its exported modules like this: https://unpkg.com/dagre-d3@0.6.1/lib/dagre.js
/* global window */
var dagre;
if (require) {
try {
dagre = require("dagre");
} catch (e) {}
}
if (!dagre) {
dagre = window.dagre;
}
module.exports = dagre;
The way this manifests is that, at runtime, any code attempting to reference one of these modules (dagre in this case) will instead resolve to undefined.
馃悰 bug report
Hi there!
I'm running into an issue where Parcel's JavaScript transformer is replacing
require
in output bundles in ways that is causing a runtime error.It looks like this might be intentional behavior (#6260) that was added for compatibility with Browserify but it seems like it's maybe not working properly in this case.
馃帥 Configuration (.babelrc, package.json, cli command)
Here's a repository setup with reproduction steps: https://github.com/natan-stripe/parcel-undefined-require/tree/main
Given input like this:
馃 Expected Behavior
I'd expected transformed output like this:
馃槸 Current Behavior
Instead we get transformed output like this:
The issue is really the
undefined
there on the 3rd line.馃拋 Possible Solution
I think probably the bug is coming from some of the logic here: https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/core/src/dependency_collector.rs#L695-L719 but I'm extremely unfamiliar with the rust code in the JavaScript transformer.
馃敠 Context
This is causing an issue in one of our applications that has a dependency on
dagre-d3
, which basically structure all of its exported modules like this: https://unpkg.com/dagre-d3@0.6.1/lib/dagre.jsThe way this manifests is that, at runtime, any code attempting to reference one of these modules (
dagre
in this case) will instead resolve to undefined.馃捇 Code Sample
https://github.com/natan-stripe/parcel-undefined-require/tree/main
馃實 Your Environment
The text was updated successfully, but these errors were encountered: