parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.52k stars 2.27k forks source link

Similar URLs with query parameters cause "Bundles must have unique names" error #7824

Open scoopandrun opened 2 years ago

scoopandrun commented 2 years ago

🐛 bug report

When building/watching/serving a web application with links pointing to the same page, but including query parameters, Parcel tries to create multiple bundles for the same page, but fails due to name conflict.

This simple example will fail to build due to bundle name conflict:

<a href="./page.html">Link without parameters</a>
<a href="./page.html?id=1">Link with parameters</a>

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

{
  "source": "src/index.html",
  "scripts": {
    "serve": "parcel",
    "watch": "parcel watch",
    "build": "parcel build"
  },
  "devDependencies": {
    "parcel": "^2.3.2"
  }
}

🤔 Expected Behavior

Parcel should create only 1 bundle and the building process should complete successfully.

😯 Current Behavior

Building fails due to HTML pages being treated as different bundles with the same name when there should only be a single bundle.

The error below is taken from the reproducible example.

🚨 Build failed.

Error: Bundles must have unique names, found dist/page.html (x2)

  AssertionError [ERR_ASSERTION]: Bundles must have unique names, found dist/page.html (x2)
  at BundlerRunner.nameBundles (C:\...\parcel-issue\node_modules\@parcel\core\lib\requests\BundleGraphRequest.js:357:23)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async BundlerRunner.bundle (C:\...\parcel-issue\node_modules\@parcel\core\lib\requests\BundleGraphRequest.js:286:5)
  at async RequestTracker.runRequest (C:\...\parcel-issue\node_modules\@parcel\core\lib\RequestTracker.js:725:20)
  at async Object.run (C:\...\parcel-issue\node_modules\@parcel\core\lib\requests\ParcelBuildRequest.js:62:7)
  at async RequestTracker.runRequest (C:\...\parcel-issue\node_modules\@parcel\core\lib\RequestTracker.js:725:20)
  at async Parcel._build (C:\...\parcel-issue\node_modules\@parcel\core\lib\Parcel.js:397:11)
  at async Parcel.run (C:\...\parcel-issue\node_modules\@parcel\core\lib\Parcel.js:276:18)
  at async run (C:\...\parcel-issue\node_modules\parcel\lib\cli.js:374:7)

💁 Possible Solution

Unless query parameters play an important role in creating separate bundles, Parcel should ignore them in links.

🔦 Context

💻 Code Sample

Simple example: https://github.com/ScoopAndrun/parcel-issue

🌍 Your Environment

Software Version(s)
Parcel 2.3.2
Node 16.14.0
npm/Yarn npm 8.3.1
Operating System Windows 10
github-actions[bot] commented 2 years ago

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.

xluanlhc commented 1 year ago

We observed the same issue in version 2.8.3

mjep commented 12 months ago

I'm having the same problem. I've got two links in an html document to the same destination but with a different query string appended to each url, e.g. :

?product-id=123456

?product-id=789012

any help would be much appreciated

I'm getting:

Build failed.

Error: Bundles must have unique name. Conflicting names:

It seems to work with full URL's not relative ones

emmanuelangola commented 6 months ago

Same for me, this has been an ongoing bug with parcelJs that hasn't been solved yet. Is there a workaround @mischnic

github-actions[bot] commented 1 week ago

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.