rollup-plugin-rename-node-modules icon indicating copy to clipboard operation
rollup-plugin-rename-node-modules copied to clipboard

Source map generated by rollup-plugin-rename-node-modules is invalid

Open SuperSodaSea opened this issue 1 year ago • 0 comments

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:

https://github.com/Lazyuki/rollup-plugin-rename-node-modules/blob/16f014311d03b14a3fbafced3931860d15948d96/src/index.ts#L106

generateMap need argument such as { source: '...', file: '...', includeContent: true } to generate the correct source map.

SuperSodaSea avatar Feb 23 '23 16:02 SuperSodaSea