diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index cd8b2dfaa33b2d..18b8ef1d252037 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -488,6 +488,9 @@ function rustifyOptionEnv( })) } +const normalizePathOnWindows = (p: string) => + path.sep === '\\' ? p.replace(/\\/g, '/') : p + // TODO(sokra) Support wasm option. function bindingToApi( binding: RawBindings, @@ -875,13 +878,23 @@ function bindingToApi( ) } + // These are relative paths, but might be backslash-separated on Windows + nextConfigSerializable.distDir = normalizePathOnWindows( + nextConfigSerializable.distDir + ) + nextConfigSerializable.distDirRoot = normalizePathOnWindows( + nextConfigSerializable.distDirRoot + ) + // loaderFile is an absolute path, we need it to be relative for turbopack. if (nextConfigSerializable.images.loaderFile) { nextConfigSerializable.images = { ...nextConfigSerializable.images, loaderFile: './' + - path.relative(projectPath, nextConfigSerializable.images.loaderFile), + normalizePathOnWindows( + path.relative(projectPath, nextConfigSerializable.images.loaderFile) + ), } } @@ -889,9 +902,11 @@ function bindingToApi( if (nextConfigSerializable.cacheHandler) { nextConfigSerializable.cacheHandler = './' + - (path.isAbsolute(nextConfigSerializable.cacheHandler) - ? path.relative(projectPath, nextConfigSerializable.cacheHandler) - : nextConfigSerializable.cacheHandler) + normalizePathOnWindows( + path.isAbsolute(nextConfigSerializable.cacheHandler) + ? path.relative(projectPath, nextConfigSerializable.cacheHandler) + : nextConfigSerializable.cacheHandler + ) } if (nextConfigSerializable.cacheHandlers) { nextConfigSerializable.cacheHandlers = Object.fromEntries( @@ -902,9 +917,11 @@ function bindingToApi( .map(([key, value]) => [ key, './' + - (path.isAbsolute(value) - ? path.relative(projectPath, value) - : value), + normalizePathOnWindows( + path.isAbsolute(value) + ? path.relative(projectPath, value) + : value + ), ]) ) }