Skip to content
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

Make Vite work with pnpm #324

Closed
intrnl opened this issue Jun 1, 2020 · 9 comments
Closed

Make Vite work with pnpm #324

intrnl opened this issue Jun 1, 2020 · 9 comments

Comments

@intrnl
Copy link
Contributor

intrnl commented Jun 1, 2020

Is your feature request related to a problem? Please describe.
pnpm is a nice package manager where packages are symlinked from a global store.
by default, it doesn't create flat node modules like npm or yarn v1 does, which is good, but many packages suffer from importing things that it didn't explicitly declare on package.json.

in the case of vite however, it's about not being able to resolve the symlinks that pnpm creates.

see this repo for an example, it relies on @intrnl/substate, which depends on immer, but since we're using pnpm, immer isn't in the top level directory.

Describe the solution you'd like
vite being able to resolve dependencies of a package on a project that uses pnpm.

Describe alternatives you've considered
using --shamefully-hoist to hoist all packages and create a flat node modules, this doesn't seem like a good idea however.

@lukeed
Copy link

lukeed commented Jun 2, 2020

Nice~! Just tried out the preact template using pnpm@5.
Currently requires pnpm install --shamefully-hoist to setup dependency linking fully.

@yyx990803
Copy link
Member

@lukeed hmm, can you provide a repro? It shouldn't require hoisting.

@yyx990803
Copy link
Member

@lukeed hmm interesting, I see the problem. Only tested vue and react templates...

@yyx990803
Copy link
Member

Ah, the prefresh plugin injects code that imports from @prefresh/core, which is a nested dep of @prefresh/vite and not directly declared in the project. This might need to be fixed on @prefresh/vite's end by re-exporting the necessary imports from itself.

@lukeed
Copy link

lukeed commented Jun 2, 2020

Yeah, I haven't tested all the templates, but I only know of the flag because it's a bit of a common "problem" with pnpm. Most of the time it's dependencies not explicitly listing a package as a peer/direct dependency, and so (by default) pnpm is assuming it's free to nest items where they're said to be needed.

Shameless hoisting flattens everything, allowing deps to access each other as siblings / from the common node_modules scope.

@yyx990803
Copy link
Member

preactjs/prefresh#75

@lukeed
Copy link

lukeed commented Jun 2, 2020

Actually in this particular case, I'm not sure what actually needs to be done since @prefresh/vite does declare @prefresh/core as a direct dependency – pnpm just moves @prefresh/core into node_modules/.pnpm/* by default.

I'll make a suggestion over in the ticket you created.

@yyx990803
Copy link
Member

The injected code is injected into user source code and run in the context of the project, not as a file under @prefresh/vite.

@lukeed
Copy link

lukeed commented Jun 2, 2020

Right, or under any directory scope that vite is looking at (or should be willing to look at) 👍

Thanks for quick responses

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants