Open fionawhim opened 4 years ago
Hrm. This issue might actually be “why doesn’t @rollup/plugin-inject correctly replace global
when Rollup is run by Snowpack / esinstall.
Sorry I might have jumped the gun filing thing this. Digging more.
@fionawhim You just saved me a lot of time trying to get to the bottom of this, thank you!
It seems rollup-plugin-inject
is not following symlinks either, but the following workaround did it for my case (with all linked packages being directly in the repository root):
import nodePolyfills from "rollup-plugin-node-polyfills";
...
plugins: [
...
nodePolyfills({
include: '../**/node_modules/**/*.js'
}),
...
]
It's a bit nasty, but a lot better than my previous workaround :D
[heavily edited to match what the source of the bug is]
The default
include
option that’s passed torollup-plugin-inject
,'node_modules/**/*.js'
, causes problems when working in a monorepo wherenode_modules
dependencies are hoisted above the current working directory whererollup
is run.The
include
ends up getting resolved relative to the current directory, even though the Node resolution might find modules in anode_modules
directory in a parent.For me, this manifested in the
buffer-es6.js
’sglobal
not getting converted into its own polyfill, which caused anUncaught ReferenceError: global is not defined
error.A workaround is to manually specify an
include
option to therollup-plugin-node-polyfills
.