#2601·wxt

wxt prepare crashes when an imported dependency reads window.location

Author: cucumber-spCreated Aug 26, 2026Updated Aug 26, 2026

Describe the bug

wxt prepare evaluates JavaScript entrypoints in WXT's Vite inline extension environment. That environment defines window and document through LinkeDOM, but provides neither window.location nor the global location.

Browser-detecting dependencies therefore conclude they are running in a browser and can crash during module initialization. Axios 1.18.1 is a concrete minimal example: it sees both globals and reads window.location.href, which throws before WXT can generate types.

Expected: wxt prepare can import a content-script definition whose dependency reads standard browser location state.

Actual:

WXT 0.21.4
ℹ Generating types...
✖ Command failed

ERROR  Cannot read properties of undefined (reading 'href')
  at node_modules/axios/lib/platform/common/utils.js:44:50
  at async eval (example.content.ts:6:31)

This appears to be a follow-on to #864. That fix intentionally supplied browser globals for entrypoint evaluation, and the discussion noted that window.location.href was not implemented. A transitive dependency can access it during ESM initialization even when application code keeps browser access inside main().

A possible fix would be to give the entrypoint environment a minimal consistent location value on both window.location and global location, or otherwise avoid exposing the partial window/document pair that triggers browser detection.

Reproduction

https://gist.github.com/cucumber-sp/d50e09a9cf76827fca08a09dcc8c428f

Steps to reproduce

bash
git clone https://gist.github.com/d50e09a9cf76827fca08a09dcc8c428f.git wxt-location-repro
cd wxt-location-repro
bun install --ignore-scripts
bun run prepare

The Axios-derived value is deliberately used in the content-script definition so WXT's metadata importer cannot tree-shake the dependency as main()-only code.

System Info

bash
System:
  OS: macOS 26.5.2
  CPU: (12) arm64 Apple M4 Pro
  Memory: 1.44 GB / 24.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 26.7.0 - /opt/homebrew/bin/node
  npm: 11.19.0 - /opt/homebrew/bin/npm
  pnpm: 11.5.1 - /opt/homebrew/bin/pnpm
  bun: 1.4.0 - /opt/homebrew/bin/bun
Browsers:
  Chrome: 151.0.7922.174
  Safari: 26.5.2
npmPackages:
  axios: 1.18.1 => 1.18.1
  vite: 8.2.1 => 8.2.1
  wxt: 0.21.4 => 0.21.4

Used Package Manager

bun

Validations

  • Read the contributing guidelines.
  • Read the installation documentation.
  • Searched open and closed issues for an existing report.
  • Confirmed this is a concrete bug rather than a usage question.
  • Provided a minimal reproducible example.