@@ -283,17 +283,33 @@ export class PnpInstaller implements Installer {
283283 }
284284
285285 if ( pnpPath . main . endsWith ( `.cjs` ) ) {
286- await xfs . writeFilePromise ( pnpPath . esmLoader , `import { syncBuiltinESMExports, createRequire } from 'module';
286+ await xfs . writeFilePromise ( pnpPath . esmLoader , `import { syncBuiltinESMExports, createRequire, builtinModules } from 'module';
287+ import { fileURLToPath, pathToFileURL, URL } from 'url';
287288syncBuiltinESMExports();
288289
289290const pnpapi = createRequire(import.meta.url)('pnpapi');
290291
291- export async function resolve(specifier, context) {
292+ function isValidURL(str) {
293+ try {
294+ new URL(str);
295+ return true;
296+ } catch {
297+ return false;
298+ }
299+ }
300+
301+ const builtins = new Set([...builtinModules]);
302+
303+ export async function resolve(specifier, context, defaultResolver) {
304+ if (builtins.has(specifier) || isValidURL(specifier)) {
305+ return defaultResolver(specifier, context, defaultResolver);
306+ }
307+
292308 const { parentURL = null } = context;
293309
294310 const resolvedPath = pnpapi.resolveRequest(
295- specifier.replace('file:///', '') ,
296- parentURL && parentURL.replace('file:///', '')
311+ specifier,
312+ parentURL ? fileURLToPath(parentURL) : undefined
297313 );
298314
299315 if (!resolvedPath) {
@@ -303,7 +319,7 @@ export async function resolve(specifier, context) {
303319 }
304320
305321 return {
306- url: new URL(\`file:///\${ resolvedPath}\` ).href,
322+ url: pathToFileURL( resolvedPath).href,
307323 };
308324}
309325 ` ) ;
0 commit comments