From 23826274b72195bb4e9cc24ddcea9b9932953887 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Tue, 16 Apr 2024 19:13:34 -0700 Subject: [PATCH] fix(turbopack-node) postcss.config.js path resolution on Windows (#7995) Absolute paths don't work for imports on windows because `c:\` is interpreted as a URI scheme. The workaround is to use an unambiguous `file://` URI. Fixes https://github.com/vercel/next.js/issues/63755 Similar to https://github.com/vercel/next.js/pull/64386 --- crates/turbopack-node/src/transforms/postcss.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-node/src/transforms/postcss.rs b/crates/turbopack-node/src/transforms/postcss.rs index c0b3a2875deb7..05e423ebf156b 100644 --- a/crates/turbopack-node/src/transforms/postcss.rs +++ b/crates/turbopack-node/src/transforms/postcss.rs @@ -248,13 +248,18 @@ pub(crate) async fn config_loader_source( // Bundling would break the ability to use `require.resolve` in the config file. let code = formatdoc! { r#" - const configPath = `${{process.cwd()}}/{config_path}`; + import {{ pathToFileURL }} from 'url'; - const mod = await __turbopack_external_import__(configPath); + const configPath = `${{process.cwd()}}/${{{config_path}}}`; + // Absolute paths don't work with ESM imports on Windows: + // https://github.com/nodejs/node/issues/31710 + // convert it to a file:// URL, which works on all platforms + const configUrl = pathToFileURL(configPath).toString(); + const mod = await __turbopack_external_import__(configUrl); export default mod.default ?? mod; "#, - config_path = config_path, + config_path = serde_json::to_string(&config_path).expect("a string should be serializable"), }; Ok(Vc::upcast(VirtualSource::new(