Description
Describe the bug
In the entrypoints, if a destructuring assignment is performed outside of the define function and references that variable, the build fails.
Reproduction
For example, the code that fails in entrypoints/background.ts
is as follows:
const [ a ] = [ 123, 456 ];
// or object as well,
// const { a } = { a: 123 };
console.log(a);
export default defineBackground(() => {
console.log('Hello background!', { id: browser.runtime.id });
});
The build failure message is as follows:
$ npm run build
> wxt-starter@0.0.0 build
> wxt build
WXT 0.19.27 7:35:16 PM
ℹ Building chrome-mv3 for production with Vite 6.0.8 7:35:16 PM
✖ Command failed after 566 ms 7:35:17 PM
ERROR a is not defined 7:35:17 PM
at entrypoints/background.ts:2:1
at ViteNodeRunner.runModule (node_modules/vite-node/dist/client.mjs:401:5)
at ViteNodeRunner.directRequest (node_modules/vite-node/dist/client.mjs:381:5)
at ViteNodeRunner.cachedRequest (node_modules/vite-node/dist/client.mjs:206:14)
at ViteNodeRunner.executeFile (node_modules/vite-node/dist/client.mjs:169:12)
at node_modules/wxt/dist/core/builders/vite/index.mjs:245:29
at async Promise.all (index 0)
at Object.run (node_modules/wxt/dist/core/utils/environments/environment.mjs:13:14)
at Object.importEntrypoints (node_modules/wxt/dist/core/builders/vite/index.mjs:242:23)
at node_modules/wxt/dist/core/utils/building/find-entrypoints.mjs:139:19
However, if the variable reference is within a define function, it succeeds.
const [ a ] = [ 123, 456 ];
export default defineBackground(() => {
console.log(a);
console.log('Hello background!', { id: browser.runtime.id });
});
Or, if no destructuring assignment is done, it will succeed.
In the success example, it can be seen that the value is output to the console.
const a = [ 123, 456 ][0];
console.log(a);
export default defineBackground(() => {
console.log('Hello background!', { id: browser.runtime.id });
});
Steps to reproduce
This can be seen immediately on the demo project created by npx wxt@latest init
.
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
Memory: 11.79 GB / 15.58 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.14.0 - ~/.local/share/pnpm/node
npm: 10.9.2 - ~/.local/share/pnpm/npm
pnpm: 9.12.3 - ~/.local/share/pnpm/pnpm
Browsers:
Chromium: 133.0.6943.141
npmPackages:
wxt: ^0.19.13 => 0.19.27
Used Package Manager
npm
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.