#.vite/deps is overriding an npm link of a package, optimizeDeps does not disable this.

3 messages · Page 1 of 1 (latest)

craggy yacht
#

Hello I've come across a problem when trying to link an NPM package.

cd my-package
npm link
npm install
npm run build
cd my-project
// cat package.json // my-package is installed from remote host but I am going to npm link it next step.
npm link my-package
npm run start (an electron application)

When my application builds the electron application finds my-project/node_modules/.vite/deps/my-package which is a cached version of the package I think because of the package.json even though I have used npm link.

The issue is:

  1. I do the npm linking steps
  2. I rm -rf node_modules
  3. I start my project
  4. It loads the linked package
  5. I close the app
  6. I boot the app
  7. The application now loads from my-project/node_modules/.vite/deps/my-package which is not my linked package!
  8. On application boot 0th, it will read from my linked package
  9. On application boot N+1, it will read from the .vite/deps which I cannot control?

My work around is doing

// in package.json
{
 "my-package":"file:..<path-on-disk>"
}

Why if I have the package installed in my-project can't I do a npm link for that package and have it work?
Why does vite look at the wrong package?

  • It looks at my-project/node_modules/.vite/deps/my-package instead of my-project/node_modules/my-package. This is wrong. I used my npm link version not some "cached" version I didn't request.
buoyant cypress
#

This is probably not a Vite issue, but an NPM issue. If you link a package, you cannot have it installed. However, I cannot say this for sure.

What I do: Don't think about it. If I want to test a new package version, I just uninstall the published version first, then link.

craggy yacht
#

Thanks for the tip.

I am not trying to say vite is right or wrong, all I am saying is it is aggresively caching npm packages and loading them in the .vite/deps cache and does not play well with linked pacakges.

I was unable to turn this off or I am curious if they have an opinion on how to handle linked packages.