Describe the bug
If I use
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
worker.js will not be packaged.
This is the recommended way to package a Worker according to vite: https://v3.vitejs.dev/guide/features.html.
Reproduction
Archive.zip
Steps to reproduce
pnpm install.
From the output, you can see that worker.js and sqlite3.wasm are not bundled.
The reason is that in defineImportMeta.mjs shipped by wxt, import.meta.url is replaced by self.location.href. This confused the bundler.
This seems to be related to #392. Personally, I don't think such substitution makes any sense on wxt level given such severe side effects, which confused vite's recommend pattern. If a user need this workaround for some packages, they may apply it themselves in their config. Once applied, it is hard to find and remove this define.
System Info
System:
OS: Linux 6.18 EndeavourOS
CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
Memory: 84.63 GB / 125.73 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 22.21.1 - /home/yichaozhou/.nix-profile/bin/node
Yarn: 1.22.22 - /usr/bin/yarn
npm: 10.9.4 - /home/yichaozhou/.nix-profile/bin/npm
pnpm: 10.25.0 - /usr/bin/pnpm
Browsers:
Firefox: 146.0.1
Firefox Developer Edition: 146.0.1
npmPackages:
wxt: ^0.20.6 => 0.20.13
Used Package Manager
pnpm
Validations
Describe the bug
If I use
worker.jswill not be packaged.This is the recommended way to package a Worker according to vite: https://v3.vitejs.dev/guide/features.html.
Reproduction
Archive.zip
Steps to reproduce
pnpm install.From the output, you can see that worker.js and sqlite3.wasm are not bundled.
The reason is that in
defineImportMeta.mjsshipped bywxt,import.meta.urlis replaced byself.location.href. This confused the bundler.This seems to be related to #392. Personally, I don't think such substitution makes any sense on
wxtlevel given such severe side effects, which confused vite's recommend pattern. If a user need this workaround for some packages, they may apply it themselves in their config. Once applied, it is hard to find and remove thisdefine.System Info
System: OS: Linux 6.18 EndeavourOS CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor Memory: 84.63 GB / 125.73 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 22.21.1 - /home/yichaozhou/.nix-profile/bin/node Yarn: 1.22.22 - /usr/bin/yarn npm: 10.9.4 - /home/yichaozhou/.nix-profile/bin/npm pnpm: 10.25.0 - /usr/bin/pnpm Browsers: Firefox: 146.0.1 Firefox Developer Edition: 146.0.1 npmPackages: wxt: ^0.20.6 => 0.20.13Used Package Manager
pnpm
Validations