Repository navigation
Description
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):
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):
- 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 hoistednode_modules/.pnpm/node_modules/<module>, silently loading the wrong version of the module even though the workspace package's ownnode_modules/<module>points to the right version. - With strict pnpm (
hoist=false): Resolving any third-party WXT module fails outright withERR_MODULE_NOT_FOUND.
Regression cause
- In WXT 0.20,
resolveWxtUserModulesusedimport-meta-resolvewithesmResolve(moduleId, pathToFileURL(path.join(root, 'index.js')).href). - chore(deps): Drop
import-meta-resolve#2526 droppedimport-meta-resolvein favor of two-argimport.meta.resolve(moduleId, importer)(whose second argument is silently ignored in Node without--experimental-import-meta-resolve). - fix: use one-arg
import.meta.resolvefor Bun compatibility #2607 dropped theimporterargument for Bun compatibility, leaving one-argimport.meta.resolve(moduleId).
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
- Extract the attached
wxt-module-resolution-repro.zip - Run:
(
pnpm install pnpm repro
pnpm reprorunspnpm --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.5Used 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.
Activity