Closed micrology closed 8 months ago
Further investigation shows that the error is generated in the parcel helper file bundle-url.js
by:
// TODO: Replace uses with `new URL(url).origin` when ie11 is no longer supported.
function getOrigin(url) {
var matches = ('' + url).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^/]+/);
if (!matches) {
throw new Error('Origin not found');
}
return matches[0];
}
and that getOrigin
is called with
url: "undefined/betweenness.7abecd3a.js"
(./js/betweenness.js
is a file in my code)
betweenness.js
is referenced in my code at:
// set up a web worker to calculate network statistics in parallel with whatever
// the user is doing
var worker = new Worker(new URL('./betweenness.js', import.meta.url), {type: 'module'})
which matches what is suggested in the parcel documentation
Possibly related to the new SWC minifier introduced in v2.9 (also reported under #9124). If you swap to using terser or esbuild as the minifier, does the issue go away?
Install terser via npm i @parcel/optimizer-terser --save-dev
and add this to your .parcelrc
file:
{
"optimizers": {
"*.js": ["@parcel/optimizer-terser"]
}
}
Then run a build and see if that fixes it.
Yes, it does fix it! Wonderful.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
🐛 bug report
Generating a web app with
npx parcel build
produces a runtime error 'Origin not found'. Doing the same, but with the--no-optimize
flag set avoids the error.🎛 Configuration (.babelrc, package.json, cli command)
🤔 Expected Behavior
No runtime error
😯 Current Behavior
Copied from DevTools: