fix: use relative paths in source maps#6450
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR updates source map path handling to use relative POSIX paths instead of absolute or webpack-specific paths, improving portability and preventing system path leakage.
- Updates
devtoolModuleFilenameTemplateto generate relative paths from the dist directory - Removes development-only condition, applying the relative path logic to all builds
- Updates test expectations to match the new relative path format (e.g.,
../src/index.tsinstead ofwebpack:///src/index.ts)
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/core/src/plugins/basic.ts | Implements relative path generation for source maps using path.relative() and removes dev-only condition |
| e2e/cases/plugin-api/plugin-transform-merge-source-map/index.test.ts | Updates test expectations to use relative paths instead of webpack protocol paths |
| e2e/cases/output/source-map/index.test.ts | Simplifies test logic and updates expected source paths to relative format |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { distPath } = api.context; | ||
|
|
||
| for (const [filename, asset] of Object.entries(assets)) { | ||
| if (!filename.endsWith('.map')) { |
There was a problem hiding this comment.
Compute relative source-map paths per environment output
The new source-map plugin derives mapDir from api.context.distPath, which is the common parent directory for all environments. When building multiple environments whose output.distPath values are nested (e.g. dist/web and dist/server), asset filenames are relative to each environment’s own output path, so combining them with the common root drops the environment subfolder. The subsequent path.relative(mapDir, source) therefore emits paths like ../../../src/foo.ts that resolve to <dist>/src/foo.ts instead of the real project source, breaking source map resolution for any environment that does not emit directly into the shared root. Use the environment-specific path (e.g. compilation.outputOptions.path or the environment.distPath passed to the hook) when computing mapDir to keep the relative paths correct.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I will verify this issue and create another PR to fix it.

Summary
Update source map paths to use relative POSIX paths instead of absolute or webpack-specific paths.
Related Links
webpack://& make sourcemaps have relative paths to original files and improve default source map behaviour for Node users webpack/webpack#3603Checklist