diff --git a/.changeset/assets-loader-posix-public-path.md b/.changeset/assets-loader-posix-public-path.md new file mode 100644 index 000000000..32c73ba04 --- /dev/null +++ b/.changeset/assets-loader-posix-public-path.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": patch +--- + +Fix the assets loader failing on Windows. Public paths for both remote and extracted assets were joined with `path.join`, which rewrites the separators to backslashes on Windows; for remote assets that turned `https://…` into a string `new URL` rejects, so any bundle containing a remote asset failed with `TypeError: Invalid URL`. Both are URLs rather than filesystem paths and are now joined with `path.posix.join`, which produces the same output on Linux and macOS as before. diff --git a/packages/repack/src/loaders/assetsLoader/convertToRemoteAssets.ts b/packages/repack/src/loaders/assetsLoader/convertToRemoteAssets.ts index 3b3b08572..b8e95f1a4 100644 --- a/packages/repack/src/loaders/assetsLoader/convertToRemoteAssets.ts +++ b/packages/repack/src/loaders/assetsLoader/convertToRemoteAssets.ts @@ -26,8 +26,10 @@ export function convertToRemoteAssets({ .join(assetsDirname, resourceDirname) .replace(pathSeparatorRegexp, '/'); - // works on both unix & windows - const publicPathURL = new URL(path.join(remotePublicPath, assetPath)); + // `remotePublicPath` is a URL, not a filesystem path, so it is joined with + // `path.posix` — `path.join` would rewrite the separators on Windows and + // produce something `new URL` rejects. + const publicPathURL = new URL(path.posix.join(remotePublicPath, assetPath)); const size = getAssetSize(assets); diff --git a/packages/repack/src/loaders/assetsLoader/extractAssets.ts b/packages/repack/src/loaders/assetsLoader/extractAssets.ts index f50d91e80..665182c4d 100644 --- a/packages/repack/src/loaders/assetsLoader/extractAssets.ts +++ b/packages/repack/src/loaders/assetsLoader/extractAssets.ts @@ -36,7 +36,10 @@ export function extractAssets( .replace(pathSeparatorRegexp, '/'); if (customPublicPath) { - publicPath = path.join(customPublicPath, publicPath); + // `publicPath` is served over HTTP and always uses forward slashes, so it + // is joined with `path.posix` regardless of the platform the bundle is + // built on. + publicPath = path.posix.join(customPublicPath, publicPath); } const size = getAssetSize(assets);