"Dynamic module" error from virtual-dom dependency global
garyb opened this issue · 3 comments
(purs plugin) Dynamic module
node_modules\global\document.js
https://www.npmjs.com/package/global
edit: it also raises a "Dynamic exports" error
It's just warning that the package is using CommonJS in a dynamic way, which isn't allowed with ES6 modules.
The problem is that the module.exports
isn't at the top level, and that isn't allowed with ES6 modules, because all imports/exports must be at the top level.
It could be fixed by changing the code to this:
if (typeof document !== 'undefined') {
var doccy = document;
} else {
var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
if (!doccy) {
doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
}
}
module.exports = doccy;
If you want better support for dynamic CommonJS, you might want to try the rollup-plugin-commonjs
plugin instead. If you use include
and exclude
you can use it at the same time as rollup-plugin-purs
:
import purs from "rollup-plugin-purs";
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
export default {
entry: "src/Main.purs",
dest: "bundle.js",
format: "iife",
sourceMap: true,
plugins: [
purs({
exclude: "node_modules/**"
}),
resolve(),
commonjs({
include: "node_modules/**"
})
]
};
Okay, I created a pull request for the global
package, but there may be some other packages that need to be fixed as well.
I figured out a way to compile module.exports
even when it's not at the top-level, so this should work now.