Skip to content
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

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

Open
SuperSodaSea opened this issue Feb 23, 2023 · 0 comments
Open

Comments

@SuperSodaSea
Copy link

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:

chunkInfo.map = magicString.generateMap();

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant