-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Dependency Optimization in pnpm #16293
Comments
You might be experiencing this situation https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude In
|
@hi-ogawa, thank you for pointing out the possible workaround involving This is particularly critical for our workflow because, although we develop in a monorepo and distribute our packages by publishing them, we encountered this issue on release day. After publishing, when attempting to consume these packages in a new Vite-based app (polyrepo), the discrepancies between monorepo and polyrepo environments in Vite became apparent. This inconsistency hampers our ability to safely develop and test packages, given that the behavior in a monorepo vs. a polyrepo setup with Vite differs significantly. As an attempt to mimic how Vite processes our packages in a polyrepo, we even tried renaming the packages folder in our monorepo to Given this context, I believe it’s reasonable to expect that if we need to explicitly include dependencies using |
Actually this type of inconsistency might be somewhat common and I experienced this myself a few times already (my framework and also Vitest's browser mode). Maybe Vite team knows something, but as far as I know this is an unfortunate situation and what I can suggest is to setup some integration tests for fresh package install scenario, which I just happen to do this recently like here https://github.com/hi-ogawa/vite-plugins/blob/992368d0c2f23dbb6c2d8c67a7ce0546d610a671/packages/react-server/misc/test.sh#L16. |
I've investigated a bit more and I have a working solution for the minimal repro (see https://github.com/front-commerce/vite-pnpm-deps-optimization/pull/3/files) with an esbuild plugin marking the package as But this solution doesn't work on our more complex application (with aliases, ssr excludes, vite ran from JS API etc…), so I'm not sure 😕 Alternatives I could find all required some changes in the core. Here are ideas:
Does anyone has any thought about these possible solutions? |
I cannot comment much of the implementation, but FYI, recently there was a discussion about how Vite team thinks about current Also just another idea to spot inconsistency between dev/build early, I was thinking you could try But I feel this would worsen DX a lot and it might be easier to setup integration tests with Btw, also looking at front-commerce/vite-pnpm-deps-optimization#3, is it different from adding |
Trying to understand the idea of front-commerce/vite-pnpm-deps-optimization#3, maybe you're looking for some ideal (hypothetical) syntax like this? optimizeDeps: {
exclude: ["@test-pkg/hello-world"], // `@test-pkg/hello-world` itself needs to be processed by Vite
include: ["@test-pkg/hello-world > *"], // but any deps from it can be always pre-bundled by esbuild
} which somewhat reminds me of how Vitest's browser mode struggles with
|
@hi-ogawa I'm having a similar issue with the With NPM, I've tried with The current workaround is adding |
@frandiox I thought Though Regarding |
Yeah that works. I started adding |
I can confirm an issue with
I've made a highly simplified Vite repo which showcases the problem: https://github.com/yairEO/vite-pnpm-bug-report-16293 My machine:
|
Describe the bug
There seems to be an issue with the optimization of cjs packages inside another package when using pnpm as the package manager, specifically in a polyrepo setup. This problem does not occur when using npm or in a monorepo setup, indicating a potential discrepancy in how dependencies resolved.
Reproduction
https://github.com/front-commerce/vite-pnpm-deps-optimization
Steps to reproduce
cd polyrepo
.pnpm run dev:pnpm
.System Info
Used Package Manager
pnpm
Logs
dev debug in pnpm
Build debug in pnpm
Validations
Possible related issues
The text was updated successfully, but these errors were encountered: