ionic-team / rollup-plugin-node-polyfills

MIT License
139 stars 59 forks source link

Default "include" option fails for monorepos #17

Open fionawhim opened 4 years ago

fionawhim commented 4 years ago

[heavily edited to match what the source of the bug is]

The default include option that’s passed to rollup-plugin-inject, 'node_modules/**/*.js', causes problems when working in a monorepo where node_modules dependencies are hoisted above the current working directory where rollup is run.

The include ends up getting resolved relative to the current directory, even though the Node resolution might find modules in a node_modules directory in a parent.

For me, this manifested in the buffer-es6.js’s global not getting converted into its own polyfill, which caused an Uncaught ReferenceError: global is not defined error.

A workaround is to manually specify an include option to the rollup-plugin-node-polyfills.

fionawhim commented 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.

fhd commented 3 years ago

@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