7.1.3 --> 8.0.0 regression: possibly pnpm related?
I build using vite and pnpm. In 7.1.3 everything was WAI with no additional options specified.
With 8.0.0 my builds are broken and the source map includes entries such as:
../lib/some_usual_and_expected_file.ts
../node_modules/.pnpm/@[email protected]/node_modules/@lit/reactive-element/css-tag.js
../node_modules/.pnpm/[email protected]/node_modules/lodash-es/_root.js
Has something regressed in terms of pnpm support?
Has something regressed in terms of pnpm support?
Nothing that I am aware of.
Is your build still ok with 7.1.3?
Yes, the build still works at 7.1.3.
Was afraid you would say that :)
Could you please provide a repro so I can investigate?
Finally got back to this 😅
Steps to reproduce:
- Clone https://github.com/zmullett/rollup-plugin-node-externals-v8-repro.
- Ensure you have pnpm installed.
- Run
pnpm i- observe thatrollup-plugin-node-externals@7is used. - Run
pnpm build- first observe that the generated filedist/rollup-plugin-node-externals-v8-repro.mjshas only animportstatement - this is the expected behavior. - Run
pnpm i rollup-plugin-node-externals@8to upgrade. - Run
pnpm buildagain - now observe that the generated filedist/rollup-plugin-node-externals-v8-repro.mjsincludes the module that should only have been imported as earlier - this is the bug.
Thank you for the repro.
From what I see, this is not an issue with pnpm but with Vite.
If you move the plugin from build.rollupOptions.plugins to the top-level plugins array in vite.config.js:
export default defineConfig({
build: {
lib: {
entry: resolve('index.js'),
formats: ['es'],
},
rollupOptions: {
plugins: [
// nodeExternals() // <-- move from here...
],
},
},
plugins: [
nodeExternals() // <-- to here
]
})
then the build works as expected.
I am not sure why but clearly, Vite treats Rollup plugins a little differently.
7.1.3 did work because the resolveId hook had a order: 'pre' property; however, it caused other problems and was removed in 8.0.0 (see #33).
Right now, I don't know what I can do about this. I think the simple workaround is to either use the top-level plugins array as shown above, or stick to 7.1.3 if it works for you. 🤷♂️ I'm going to stress that point in the docs.
Confirmed, that works. Thanks for debugging and finding that difference between the plugins lists, ugh! I'll leave the ticket open in case you want to track that docs update with it.
FWIW, I found this in Vite documentation:
If a Rollup plugin only makes sense for the build phase, then it can be specified under
build.rollupOptions.pluginsinstead. It will work the same as a Vite plugin withenforce: 'post'andapply: 'build'.
8.0.1 is out with an updated README, now closing this issue. Thanks again!