wxt: Uncaught (in promise) ReferenceError: window is not defined
Describe the bug
Tried with 0.19.2 and 0.18.15.
This error persists both in dev and prod builds.
Reproduction
Steps to reproduce
Just run the extension form attached archive and see.
System Info
System:
OS: macOS 14.5
CPU: (11) arm64 Apple M3 Pro
Memory: 76.47 MB / 18.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.4.0 - ~/.nvm/versions/node/v22.4.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v22.4.0/bin/npm
pnpm: 9.6.0 - ~/.nvm/versions/node/v22.4.0/bin/pnpm
bun: 1.1.18 - ~/.bun/bin/bun
Browsers:
Chrome: 127.0.6533.72
Safari: 17.5
npmPackages:
vite: ^5.3.5 => 5.3.5
wxt: ^0.18.2 => 0.18.15
Used Package Manager
pnpm
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
So just to clearify, the problem was dynamic imports in a background marked as
type: "module", right?Solutions:
type: "module"If we need to keep this open, feel free to reopen!
Right. I’ve checked that using dynamic imports in the background(with
type: "module") causes the same issue also in my project.This is a trade-off.
type: "module"in the backgroundtype: "module"in the background => avoid using dynamic imports@1natsu172, thank you. Yes, I plan to use only the synchronous implementation.
i18n-utils.async.tsis generated automatically, but I don’t use it.@amal Sorry, I was misread your message. If you keep
i18nextand settype: "module", it will output chunks in ESM format. Withouttype: "module", it defaults to CJS format, resolving as static objects, and thus, the error doesn’t occur.Dynamic import isn’t support in the background script, it might be better to use synchronous implementations instead.
I have encountered this error, which is actually an error of vite dynamic import failure. Let me guess, you used dynamic import in the background.
FYI - Background does not support the use of dynamic import. https://github.com/w3c/webextensions/issues/212