From 12a02281bccccf8fa8efde45b54368721346ae61 Mon Sep 17 00:00:00 2001 From: Aaron Queen Date: Sat, 29 Aug 2026 20:10:27 -0600 Subject: [PATCH] fix: use one-arg import.meta.resolve for Bun compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bun's two-arg import.meta.resolve(specifier, parent) fails for bare package names (Cannot find package 'wxt' / '@wxt-dev/…'). One-arg resolve works on both Bun and Node, so WXT CLI can run under bun --bun / bunx --bun. --- packages/wxt/src/core/resolve-config.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/wxt/src/core/resolve-config.ts b/packages/wxt/src/core/resolve-config.ts index c74ffbbb8..e455c91ef 100644 --- a/packages/wxt/src/core/resolve-config.ts +++ b/packages/wxt/src/core/resolve-config.ts @@ -29,7 +29,7 @@ import { getEslintVersion } from './utils/eslint'; import { safeStringToNumber } from './utils/number'; import { loadEnv } from './utils/env'; import { getPort } from 'get-port-please'; -import { fileURLToPath, pathToFileURL } from 'node:url'; +import { fileURLToPath } from 'node:url'; import { createSafariRunner } from './runners/safari'; import isWsl from 'is-wsl'; import { createWslRunner } from './runners/wsl'; @@ -545,10 +545,12 @@ async function getUnimportEslintOptions( /** Returns the path to `node_modules/wxt`. */ function resolveWxtModuleDir() { - const url = import.meta.resolve('wxt', import.meta.url); + // Prefer one-arg resolve: Bun's two-arg `import.meta.resolve(spec, parent)` + // fails for bare package names (`Cannot find package 'wxt'`). Node accepts both. + const url = import.meta.resolve('wxt'); - // esmResolve() returns the "wxt/dist/index.mjs" file, not the package's root - // directory, which we want to return from this function. + // import.meta.resolve returns the package entry (e.g. dist/index.mjs), not the + // package root directory, which we want to return from this function. return path.resolve(fileURLToPath(url), '../..'); } @@ -596,12 +598,12 @@ export async function resolveWxtUserModules( modulesDir: string, modules: string[] = [], ): Promise[]> { - const importer = pathToFileURL(path.join(root, 'index.js')).href; - // Resolve node_modules modules const npmModules = await Promise.all>( modules.map(async (moduleId) => { - const resolvedModulePath = import.meta.resolve(moduleId, importer); + // One-arg: Bun rejects two-arg resolve with a synthetic parent URL + // (`file:///…/index.js` that does not exist on disk). + const resolvedModulePath = import.meta.resolve(moduleId); const mod: { default: WxtModule } = await import( /* @vite-ignore */ resolvedModulePath );