wxt-dev / wxt-dev/wxt

wxt prepare crashes when an imported dependency reads window.location

Open
#2,601 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

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
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
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the linked example.content.ts entrypoint with bun run prepare, then trace WXT's Vite inline extension environment during entrypoint evaluation. Done means the Axios-derived import no longer crashes while WXT generates types, with consistent location behavior or without exposing a misleading partial browser environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.