Skip to content

resolveWxtUserModules resolves npm modules from wxt's own path instead of project root (regression from #2526 / #2607) #2767

Open

Description

@rxliuli

Describe the bug

In WXT 0.21 ([email protected]), resolveWxtUserModules resolves npm modules declared in wxt.config.ts (modules: [...]) using one-argument import.meta.resolve(moduleId):

https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/internal/resolve-config.ts#L589-L600

export async function resolveWxtUserModules(
  root: string,
  modulesDir: string,
  modules: string[] = [],
): Promise<WxtModuleWithMetadata<any>[]> {
  // Resolve node_modules modules
  const npmModules = await Promise.all<WxtModuleWithMetadata<any>>(
    modules.map(async (moduleId) => {
      const resolvedModulePath = import.meta.resolve(moduleId);

Because import.meta.resolve(moduleId) resolves relative to wxt's own file location (node_modules/.pnpm/wxt@.../node_modules/wxt/dist/internal/resolve-config.mjs) instead of the user's project root (which is now unused in resolveWxtUserModules):

  1. In a pnpm monorepo with multiple versions of a WXT module: Node walks up from node_modules/.pnpm/wxt@.../node_modules/wxt/ and hits pnpm's hoisted node_modules/.pnpm/node_modules/<module>, silently loading the wrong version of the module even though the workspace package's own node_modules/<module> points to the right version.
  2. With strict pnpm (hoist=false): Resolving any third-party WXT module fails outright with ERR_MODULE_NOT_FOUND.

Regression cause

Possible fix

Resolve moduleId from root (for example via createRequire(path.join(root, 'package.json')).resolve(moduleId) + pathToFileURL, or restoring import-meta-resolve), which works in both Node.js and Bun without relying on hoisting.

Reproduction

wxt-module-resolution-repro.zip

Steps to reproduce

  1. Extract the attached wxt-module-resolution-repro.zip
  2. Run:
    pnpm install
    pnpm repro
    (pnpm repro runs pnpm --filter ext-v1 exec wxt prepare && pnpm --filter ext-v2 exec wxt prepare)

Expected:

[ext-v1] loaded [email protected]
[ext-v2] loaded [email protected]

Actual (WXT 0.21.5):

[ext-v1] loaded [email protected]
[ext-v2] loaded [email protected]

ext-v2 depends on [email protected], but WXT loads [email protected] from pnpm's hoisted .pnpm/node_modules.

System Info

System:
  OS: macOS 27.2.1
Binaries:
  Node: 24.22.1
  pnpm: 12.18.0
npmPackages:
  wxt: 0.21.5

Used Package Manager

pnpm

Validations

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions