rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
502 stars 126 forks source link

Global variable 'process' is conflicting with auto generated module name #309

Closed garylin closed 6 years ago

garylin commented 6 years ago

Hi, I ran into an issue where my "process" global variable is conflicting with the auto generated module name if one of the dependent file has the filename of process.js. Here is the example config & sources to reproduce the problem:

// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
    input: 'test.js',
    output: {
        file: 'bundle.js',
        format: 'cjs'
    },
    plugins: [
      resolve(),
      commonjs(),
    ]
}

And here are two files I try to rollup:

// test.js
var p = require('./process.js')
p();
// process.js
function foo() {
  console.log(process.pid)
}
module.exports = foo;

In the generate bundle, the process.js gets converted to:

....

var process = __commonjs(function (module) {
function foo() {
  console.log(process.pid);
}
module.exports = foo;
});

.... 

In the generated file, "process" used to retrieve the pid end up to become the "process" common js module. Any one know how to workaround this issue?