Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/assets-loader-posix-public-path.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion packages/repack/src/loaders/assetsLoader/extractAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading