New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken sourcemaps for two outputs of different entryFileNames in same dir #3439
Comments
For anyone running into this issue: import path from 'path';
// Fixes broken sourcemaps generated by rollup which might mess up association to a sourcemap's bundle file when writing
// multiple outputs to the same directory, see https://github.com/rollup/rollup/issues/3439.
function fixSourcemaps() {
return {
name: 'fix-sourcemaps',
generateBundle: (options, bundle) => {
for (const assetOrChunkInfo of Object.values(bundle)) {
if (!assetOrChunkInfo.map) return; // has no sourcemap
assetOrChunkInfo.map.file = path.basename(assetOrChunkInfo.fileName);
}
},
};
}
export default {
input: 'input.js',
output: [
{
dir: 'output',
format: 'es',
entryFileNames: 'bundle.es.js',
sourcemap: true,
plugins: [fixSourcemaps()],
},
{
dir: 'output',
format: 'cjs',
entryFileNames: 'bundle.cjs.js',
sourcemap: true,
plugins: [fixSourcemaps()],
},
],
}; |
Merged
9 tasks
Sorry, for this, fix at #3440 |
Respect you found such an easy workaround using the plugin API 👍 |
Awesome, thank you for the fix :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
Generated sourcemaps for individual bundles generated in an output dir should reference their respective bundle file.
Actual Behavior
All sourcemaps for bundles named via
entryFileNames
in the same output dir reference the last generated file ("file":"bundle.cjs.js"
in the example repl).Chrome DevTools fails to parse the erroneous sourcemaps.
Use case
The repl setup is somewhat artificial. The desired behavior can in the example be achieved more elegantly and without issues by using
output.file
instead ofoutput.dir
in combination withoutput.entryFileNames
. However, there are uses cases where such a setup makes sense, for example when one wants to generate declaration files with the typescript plugin which requires specifying thedir
option.The text was updated successfully, but these errors were encountered: