vite
vite copied to clipboard
Whether or not module is pre-bundled is highly sensitive to workspace dependencies
Describe the bug
I'm working on a project with the @modular-forms/solid package, which is an ESM module, so I would expect it to not be pre-bundled. However, it's pre-bundled when the following are true (I think).
- The project is a node monorepo
- The package inside the monorepo (
package_ain my case) does not have the dependencies listed in it's ownpackage.json; they're listed in the monorepopackage.jsoninstead. - You're using
bun. If you usenpm, it won't be able to find the right dependencies for some reason. - There may be other requirements, but I'm not sure.
This normally wouldn't be a problem, but it contributed to this issue: #17310.
Reproduction
https://github.com/jsimonrichard/vite-pre-bundling-issues-mre
Steps to reproduce
cd wrongly-pre-bundled/package_a
bun i
bun start
Then stop the program and inspect wrongly-pre-bundled/node_modules/.vite. The pre-bundled file for @modular-forms/solid should be present.
System Info
System:
OS: Linux 6.2 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
CPU: (24) x64 AMD Ryzen Threadripper 1920X 12-Core Processor
Memory: 44.94 GB / 62.64 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 21.6.1 - ~/.nvm/versions/node/v21.6.1/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v21.6.1/bin/npm
bun: 1.1.8 - ~/.bun/bin/bun
Browsers:
Brave Browser: 123.1.64.113
Chromium: 125.0.6422.60
Used Package Manager
bun
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
- You're using
bun. If you usenpm, it won't be able to find the right dependencies for some reason.
I'm not familiar with npm workspace features, but maybe the difference is just you forgot to run npm i inside cd wrongly-pre-bundled. It looks like npm i inside cd wrongly-pre-bundled/package_a is not enough for npm.
Other than that, the behavior looks same and the issue is essentially https://github.com/vitejs/vite/issues/17310. Can you confirm?
You're right; if I run npm i inside wrongly-pre-bundled/ then npm start inside wrongly-pre-bundled/package_a/, npm works fine. The package @modular-forms/solid is still pre-bundled, but if that's the expected behavior then feel free to close this issue.
The main issue is #17310.
Yeah, I think this one is simply a difference of npm i and bun i inside individual workspace directory, so it's not related to Vite. Closing.