question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`url:` imports fail with `Could not resolve bundle with id`

See original GitHub issue

🐛 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

parcel_lazy_error.zip

🌍 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)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
spointeckercommented, Feb 2, 2022

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:

1reaction
danieltrogercommented, Mar 4, 2022

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 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

parcel can't resolve bundle using dynamic import
I am using Parcel to bundle my Javascript files. Everything works fine when using the localhost server to test out the build, ...
Read more >
Module Resolution - Parcel
This example bundles a directory of png files and returns the dist URLs. import foo from "/assets/*.png"; // { // 'file-1': ...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >
Documentation - Module Resolution - TypeScript
We'll cover non-relative imports next. Finally, if the compiler could not resolve the module, it will log an error. In this case, the...
Read more >
JavaScript modules - MDN Web Docs
Importing modules using import maps. Above we saw how a browser can import a module using a module specifier that is either an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found