diff --git a/packages/core/src/helpers/compiler.ts b/packages/core/src/helpers/compiler.ts index 5617371a88..ec7521c2f3 100644 --- a/packages/core/src/helpers/compiler.ts +++ b/packages/core/src/helpers/compiler.ts @@ -15,7 +15,10 @@ export const getPublicPathFromCompiler = ( if (typeof publicPath === 'string') { // 'auto' is a magic value in Rspack and behave like `publicPath: ""` - if (publicPath === 'auto') { + // Empty string is a valid value representing a relative path and should be preserved + // This is important for server targets (node) to enable relative paths for worker_threads + // See: https://github.com/web-infra-dev/rsbuild/issues/6539 + if (publicPath === 'auto' || publicPath === '') { return ''; } return publicPath.endsWith('/') ? publicPath : `${publicPath}/`; diff --git a/packages/core/src/helpers/url.ts b/packages/core/src/helpers/url.ts index 1db088395a..ece1d2e5d1 100644 --- a/packages/core/src/helpers/url.ts +++ b/packages/core/src/helpers/url.ts @@ -62,7 +62,8 @@ export const formatPublicPath = ( withSlash = true, ): string => { // 'auto' is a magic value in Rspack and we should not add trailing slash - if (publicPath === 'auto') { + // Empty string is a valid value representing a relative path and should be preserved (important for node targets) + if (publicPath === 'auto' || publicPath === '') { return publicPath; }