diff --git a/.changeset/friendly-melons-argue.md b/.changeset/friendly-melons-argue.md new file mode 100644 index 000000000..c352a9f3f --- /dev/null +++ b/.changeset/friendly-melons-argue.md @@ -0,0 +1,5 @@ +--- +'@callstack/repack': patch +--- + +Fix reading `webpack.config.mjs` on Windows diff --git a/packages/repack/src/commands/utils/getWebpackConfigPath.ts b/packages/repack/src/commands/utils/getWebpackConfigPath.ts index ea285f87c..eeaa3fa8d 100644 --- a/packages/repack/src/commands/utils/getWebpackConfigPath.ts +++ b/packages/repack/src/commands/utils/getWebpackConfigPath.ts @@ -1,6 +1,7 @@ -import path from 'path'; -import fs from 'fs'; -import Os from 'os'; +import path from 'node:path'; +import fs from 'node:fs'; +import os from 'node:os'; +import url from 'node:url'; // Supports the same files as Webpack CLI. const DEFAULT_WEBPACK_CONFIG_LOCATIONS = [ @@ -22,13 +23,10 @@ export function getWebpackConfigPath(root: string, customPath?: string) { const filename = path.isAbsolute(candidate) ? candidate : path.join(root, candidate); + if (fs.existsSync(filename)) { - if ( - path.isAbsolute(candidate) && - candidate.endsWith('.mjs') && - Os.platform() === 'win32' - ) { - return `file:\\${filename}`; + if (path.extname(filename) === '.mjs' && os.platform() === 'win32') { + return url.pathToFileURL(filename).href; } else { return filename; }