Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Extensions: duplicate bundles when importing the same file via import and manifest.json #9446

Open
fregante opened this issue Dec 15, 2023 · 5 comments

Comments

@fregante
Copy link
Contributor

fregante commented Dec 15, 2023

🐛 bug report

In my extension, I mention the same file in the manifest and in a JS file. This causes Parcel to bundle the same file twice with two outputs. This in turn causes nearly every sub-import to also be duplicated. In this case the duplicate file was source/index.html (note that this screenshot was made after trash distribution && parcel build)

Screenshot

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

{
	"extends": "@parcel/config-webextension",
	"transformers": {
		"*.svelte": ["parcel-transformer-svelte"]
	}
}
{
	"@parcel/resolver-default": {
		"packageExports": true
	}
}

🤔 Expected Behavior

The file should not be duplicated.

😯 Current Behavior

Two html files appear in dist

💻 Code Sample

{
	"name": "name",
	"description": "desc",
	"version": "0.0.0",
	"manifest_version": 3,
	"action": {
		"default_popup": "index.html"
	}
	"background": {
		"service_worker": "background.js",
		"type": "module"
	},
}
// background.js

import appUrl from 'url:./index.html';
console.log(appUrl);

Full repro can be found in this PR (until commit 1009154)

Note that in my case, the manifest actually mentions index.html?type=popup, which is valid and could further cause issues, but the same bug appears even without the search parameter.

🌍 Your Environment

Software Version(s)
Parcel 2.10.3
Node v18.18.2
npm/Yarn 9.8.1
Operating System macOS
@fregante
Copy link
Contributor Author

I also tried using the same exact path in both, to no avail:

import appUrl from 'url:./index.html';
	"action": {
		"default_icon": "logo.png",
		"default_popup": "./index.html"
	},

fregante added a commit to hankxdev/one-click-extensions-manager that referenced this issue Dec 15, 2023
@mischnic
Copy link
Member

Does new URL("index.html", import.meta.url) cause the same problem?

@fregante
Copy link
Contributor Author

Yes. I also tried matching the exact string in both ways: index.html, ./index.html

@github-actions github-actions bot added Stale Inactive issues and removed Stale Inactive issues labels Jul 1, 2024
@fregante
Copy link
Contributor Author

fregante commented Jul 6, 2024

Still reproducible with today's canary. Sub-dependencies are also duplicated:

  • file.hash.html imports:
    • file.hash.css
    • file.hash.js
  • file.anotherhash.html imports:
    • file.anotherhash.css
    • file.anotherhash.js

contents are 100% match except these import paths.

@fregante
Copy link
Contributor Author

I'm seeing the same issue with just manifest.json in the latest canary after this was fixed:

The repro:

{
	"background": {
		"type": "module"
		"service_worker": "background.js",
		"scripts": [
			"background.js"
		]
	},
}

The generated background.29017fde.js and background.e1bfa0d5.js are identical except the internal module IDs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants