-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Description
Using ES Modules is fine, but require calls are behaving unexpectedly.
-
Create a file eg
/path/to/transform.js:const { a } = require('./a'); export default babel => { const { types: t } = babel; console.log(a()); return { visitor: { Program(path) { path.traverse({ enter(path) { t.removeComments(path.node); } }); } } }; };
-
Create a file eg
/path/to/a.js:module.exports = { a: () => 'AAAA' };
-
Select
babelv7in the Transform Menu -
Choose
/path/to/transform.js
Expected Output
'use strict';
const a = () => 'AAAA';
var main = babel => {
const { types: t } = babel;
console.log(a());
return {
visitor: {
Program(path) {
path.traverse({
enter(path) {
t.removeComments(path.node);
}
});
}
}
};
};
module.exports = main;Actual Output
Cannot find module './a'
rollup.js REPL Examples
-
This ES Modules example is fine.
-
This CommonJS example doesn't error like it does in Electron (Electron could be a factor) but it also doesn't bundle in the contents of
/path/to/a.js– it leaves the require calls there.
Suggested Solution
https://github.com/rollup/rollup-plugin-node-resolve and/or https://github.com/rollup/rollup-plugin-commonj might possibly be needed.
Help Needed
Ideas welcome, I'm stuck so far after an hour or two working on this.