Here is a repo reproducing the issue: https://github.com/jpaquim/rollup-monorepo-issue
Steps:
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/') or more simply dedupe: ['svelte', 'svelte/internal'].The imported package should be correctly bundled with the rest of the output.
The imported package is not resolved correctly, rollup complains: (!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
svelte/internal (imported by src/App.svelte)
Consequently, the import statement remains in the output. In my case: import { SvelteComponent, init, safe_not_equal, element, text, space, attr, insert, append, set_data, noop, detach } from 'svelte/internal';
The issue seems to be related to this line, where the importee is overwritten with join(process.cwd(), 'node_modules', importee).
In a monorepo context, process.cwd() will typically refer to the package where the rollup command is started from, but with hoisting, the relevant node_modules are actually at the root of the monorepo, thus leading to the conflict.
Thanks for the issue :beer:
This is going to be a difficult one to remedy in a monorepo. I'm afraid the setup is going to be a bit complex in order to get multiple folks working on triage. Can you provide a repo that has a reproducible setup? One with the setup you're using would be most helpful.
@shellscape sure thing, here is a repo reproducing the issue: https://github.com/jpaquim/rollup-monorepo-issue
Run yarn at the root, then navigate to packages/template and run yarn build, and you should see the resulting (!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
svelte/internal (imported by src/App.svelte) warning.
I don't have enough context on the internals of rollup or this plugin, so this will probably be na茂ve, but it seems that just replacing join(process.cwd(), 'node_modules', importee) with require.resolve(importee) seems to work for this specific case, basically letting node itself resolve the importee from the parent folders recursively.
However, I'm not sure if this would actually work inside a nested package, what the behaviour of require.resolve would be in that situation...
I've created a PR for this https://github.com/rollup/plugins/pull/98
Great, thank you @LarsDenBakker and @shellscape for the great work!
馃憤 we're still working on getting publishing smoothed out, so please have patience on that getting to NPM
Most helpful comment
I've created a PR for this https://github.com/rollup/plugins/pull/98