parcel: `url:` imports fail with `Could not resolve bundle with id`
π bug report
It seems like https://github.com/parcel-bundler/parcel/issues/4365 has risen from the dead.
When having a <script> tag with type="module" which imports something which lazily imports something which imports something using the url: scheme, running the code results in a runtime error.
π Configuration (.babelrc, package.json, cli command)
package.json:
{
"scripts": {
"build": "parcel build src/index.html",
"serve": "parcel serve src/index.html"
},
"dependencies": {
"@parcel/babel-plugin-transform-runtime": "nightly",
"@parcel/babel-preset-env": "nightly",
"@parcel/bundler-default": "nightly",
"@parcel/compressor-raw": "nightly",
"@parcel/config-default": "nightly",
"@parcel/core": "nightly",
"@parcel/css": "latest",
"@parcel/fs": "nightly",
"@parcel/namer-default": "nightly",
"@parcel/optimizer-css": "nightly",
"@parcel/optimizer-cssnano": "nightly",
"@parcel/optimizer-htmlnano": "nightly",
"@parcel/optimizer-terser": "nightly",
"@parcel/packager-css": "nightly",
"@parcel/packager-html": "nightly",
"@parcel/packager-js": "nightly",
"@parcel/packager-raw-url": "nightly",
"@parcel/resolver-default": "nightly",
"@parcel/runtime-browser-hmr": "nightly",
"@parcel/runtime-js": "nightly",
"@parcel/runtime-react-refresh": "nightly",
"@parcel/runtime-service-worker": "nightly",
"@parcel/transformer-babel": "nightly",
"@parcel/transformer-css": "nightly",
"@parcel/transformer-css-experimental": "nightly",
"@parcel/transformer-html": "nightly",
"@parcel/transformer-inline-string": "nightly",
"@parcel/transformer-js": "nightly",
"@parcel/transformer-postcss": "nightly",
"@parcel/transformer-posthtml": "nightly",
"@parcel/transformer-react-refresh-wrap": "nightly",
"@parcel/transformer-sass": "nightly",
"@parcel/transformer-webmanifest": "nightly",
"@parcel/utils": "nightly",
"parcel": "nightly"
}
}
cli command: yarn install && yarn build && http-server -p 1234 dist/
π€ Expected Behavior
The URL to the SVG should be logged to the console.
π― Current Behavior
lazy.e20bce0f.js:1 Uncaught (in promise) Error: Could not resolve bundle with id 2vcPw
at Object.r (lazy.e20bce0f.js:1:666)
at Object.<anonymous> (lazy.e20bce0f.js:1:487)
at o ((index):1:416)
at Object.<anonymous> (lazy.e20bce0f.js:1:378)
at o ((index):1:416)
at (index):1:673
at async (index):1:716
π Possible Solution
Fix so that it no longer throws but instead correctly gives the URL of the SVG.
Alternatively, please fix https://github.com/parcel-bundler/parcel/issues/5683 which forced me to use a <script> tag instead of <script src=" and triggered this error.
π¦ Context
Was happily on parcel 2.0.1. Then my colleague wanted to import a style sheet per module on our react project. Reason being readability and that unused CSS doesnβt load too early.
It worked out of the box (like parcel usually does) π but the precedence was wrong.
When doing
in entrypoint:
import "./low-precedence.scss"; // general styling
import "./script.ts";
in script.ts:
import "./high-precedence.scss";
The output bundle first contained high-precedence and then low-precedence, making it impossible to override general styling without making every selector more specific.
I was about to report an issue but then I discovered https://github.com/parcel-bundler/parcel-css, which fixed all issues and made the scss build time much faster π
Buuutt to install that I had to update to the latest parcel, where I was greeted with https://github.com/parcel-bundler/parcel/issues/5683.
After figuring out the workaround I thought I could finally be happy but then this happened π
π» Code Sample
π Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 2.0.0-nightly.984+74fcc3fb |
| Node | v17.4.0 |
| npm/Yarn | 3.1.1 |
| Operating System | macOS 12.1 (21C52) |
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 19 (6 by maintainers)
Commits related to this issue
- remove svg due to https://github.com/parcel-bundler/parcel/issues/7609 — committed to brumm/tako by brumm 10 months ago
Hey, I am also struggling with this issue. I am on Parcel v2.2.1.
In my case it only happens in production build when loading the page. The parcel build process itself works. I already tried to:
Iβm also seeing this issue with my service worker. The service worker fails to register and logs the same
could not resolve bundle with iderror message. Disabling scope hoisting fixes the registration, but the service worker does not seem to function correctly. Iβm working on narrowing down further what isnβt working. Everything builds fine with parcel 1.Scope hoisting is one of the reasons Iβm using parcel because not having it increases bundle size so unfortunately thatβs not an option for me π¦
Maybe itβs just a random coincidence, but maybe it has something to do with svgs.
I am using fontawesome svg icons, and the console shows that it is trying to load an icon:
.
I stepped a bit further and here is where it adds the reference to the unexisting SVG:
https://github.com/parcel-bundler/parcel/blob/e0440dcbe6d6e419a412c8c568d94715cdb4282a/packages/runtimes/js/src/JSRuntime.js#L191
DUnno where the place where itβs missing is though