Circular dependency when bundling
renataogarcia opened this issue · comments
renataogarcia commented
When bundling with rollup I get the following warning:
(!) Circular dependency
../node_modules/eventemitter3/index.mjs -> ../node_modules/eventemitter3/index.mjs
Then when trying to run the output I get the following error:
const EventEmitter = EventEmitter;
^
ReferenceError: Cannot access 'EventEmitter' before initialization
It works fine up to version 4.0.7
Rollup resolves the import from index.js as index.mjs which causes the circular problem.
By renaming the file to wrapper.mjs instead (same as in the node docs) I was able to get it working.
Luigi Pinca commented
I cannot reproduce the issue:
$ cat main.js
import EventEmitter from 'eventemitter3';
const ee = new EventEmitter();
ee.on('foo', function () {
console.log('Ok');
});
ee.emit('foo');
$ cat rollup.config.mjs
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
export default {
input: './main.js',
output: {
file: 'bundle.mjs',
format: 'es'
},
plugins: [commonjs(), nodeResolve()]
};
$ npx rollup -c
./main.js → bundle.mjs...
created bundle.mjs in 76ms
$ node bundle.mjs
Ok
renataogarcia commented
Thanks for looking into this.
I investigated why it's only happening in my case, and it seems that there's an issue with rollup-plugin-swc3 resolution which is causing this problem.