diff --git a/lib/internal/loader/ModuleRequest.js b/lib/internal/loader/ModuleRequest.js index 13606568c3309d..93baf2a597fc1a 100644 --- a/lib/internal/loader/ModuleRequest.js +++ b/lib/internal/loader/ModuleRequest.js @@ -36,9 +36,12 @@ loaders.set('esm', async (url) => { }); // Strategy for loading a node-style CommonJS module +const isWindows = process.platform === 'win32'; +const winSepRegEx = /\//g; loaders.set('cjs', async (url) => { const pathname = internalURLModule.getPathFromURL(new URL(url)); - const module = CJSModule._cache[pathname]; + const module = CJSModule._cache[ + isWindows ? pathname.replace(winSepRegEx, '\\') : pathname]; if (module && module.loaded) { const ctx = createDynamicModule(['default'], url, undefined); ctx.reflect.exports.default.set(module.exports);