8000 Using service worker in web extension results in 'Bundles conflicting names' error · Issue #10223 · parcel-bundler/parcel · GitHub
[go: up one dir, main page]

Skip to content

Using service worker in web extension results in 'Bundles conflicting names' error #10223

@younesaassila

Description

@younesaassila

🐛 bug report

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

I have made a GitHub repo with all the necessary config to replicate the issue here: https://github.com/younesaassila/parcel-conflicting-names

TLDR: Using @parcel/config-webextension. Extension manifest specifies a service worker (MV3-style). onInstall page has a link to the extension Options page -> this creates the error.

🤔 Expected Behavior

When using a background page/script (MV2-style), there is no issue. So MV3 should also be issue-free.

😯 Current Behavior

Building the MV3 extension results in a 'Bundles conflicting names' error:

Error: Bundles must have unique names. Conflicting names: dist/options.html

  AssertionError [ERR_ASSERTION]: Bundles must have unique names. Conflicting names: dist/options.html
      at BundlerRunner.validateBundles (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\requests\BundleGraphRequest.js:373:27)
      at BundlerRunner.bundle (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\requests\BundleGraphRequest.js:345:12)
      at async Object.run (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\requests\BundleGraphRequest.js:123:17)
      at async RequestTracker.runRequest (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\RequestTracker.js:758:20)
      at async Object.run (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\requests\ParcelBuildRequest.js:52:7)
      at async RequestTracker.runRequest (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\RequestTracker.js:758:20)
      at async Parcel._build (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\Parcel.js:320:11)
      at async Parcel.run (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\@parcel\core\lib\Parcel.js:210:18)
      at async run (C:\Users\Younes\Documents\My
  Documents\Projects\parcel-conflicting-names\node_modules\parcel\lib\cli.js:356:7)

💁 Possible Solution

From tinkering with the Parcel code, it appears that the issue is caused (in part) by this code:

env: {
context: 'service-worker',
sourceType: program.background.type == 'module' ? 'module' : 'script',
},

Removing the env {} part from this code, OR setting the asset env to service_worker at the end of WebExtensionTransformer.js """resolves""" the issue. So the issue seems to be that when there is an env context mismatch between the asset (manifest.json) and one of its dependency. Since I'm not familiar with the Parcel code/pipeline I haven't dug in further.

🔦 Context

I'm trying to add a link on the onInstall page shown to the user when first installing the extension to let them open the Options page.

💻 Code Sample

Repo available here: https://github.com/younesaassila/parcel-conflicting-names

🌍 Your Environment

Software Version(s)
Parcel 2.16.0
Node 22.20.0
npm/Yarn 11.6.2
Operating System Windows 11 24H2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0