rollup-plugin-rename-node-modules
rollup-plugin-rename-node-modules copied to clipboard
Source map generated by rollup-plugin-rename-node-modules is invalid
rollup-plugin-rename-node-modules
is not generating source map correctly. For example:
package.json
{
"type": "module",
"scripts": {
"build": "rollup -c"
},
"dependencies": {
"colord": "^2.9.3"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"rollup": "^2.79.1",
"rollup-plugin-rename-node-modules": "^1.3.1"
}
}
rollup.config.js
import nodeResolve from '@rollup/plugin-node-resolve';
import renameNodeModules from 'rollup-plugin-rename-node-modules';
export default {
plugins: [
renameNodeModules(),
nodeResolve(),
],
input: 'index.js',
output: {
dir: 'dist',
entryFileNames: '[name].mjs',
format: 'esm',
sourcemap: true,
preserveModules: true,
exports: 'named',
},
};
index.js
import { colord } from 'colord'; // Import any external package
console.log(colord(0xFF0000));
Run npm run build
, and the result dist/index.mjs.map is:
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],/* ... */}
This is obviously invalid. The correct source map should be looks like:
{"version":3,"file":"index.mjs","sources":["../index.js"],"sourcesContent":[/* ... */],/* ... */}
This issue is caused by this line of code:
generateMap
need argument such as { source: '...', file: '...', includeContent: true }
to generate the correct source map.