Skip to content

Commit

Permalink
fix(turbopack-node) postcss.config.js path resolution on Windows (#7995)
Browse files Browse the repository at this point in the history
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 vercel/next.js#63755

Similar to vercel/next.js#64386
  • Loading branch information
bgw committed Apr 17, 2024
1 parent 9d45eac commit 2382627
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2382627

Please sign in to comment.