vite icon indicating copy to clipboard operation
vite copied to clipboard

Whether or not module is pre-bundled is highly sensitive to workspace dependencies

Open jsimonrichard opened this issue 1 year ago • 1 comments

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_a in my case) does not have the dependencies listed in it's own package.json; they're listed in the monorepo package.json instead.
  • You're using bun. If you use npm, 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

jsimonrichard avatar May 25 '24 02:05 jsimonrichard

  • You're using bun. If you use npm, 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?

hi-ogawa avatar May 25 '24 03:05 hi-ogawa

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.

jsimonrichard avatar May 25 '24 14:05 jsimonrichard

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.

hi-ogawa avatar May 26 '24 00:05 hi-ogawa