Pre-Bundled dependencies used over locally linked dependency when built before linking
See original GitHub issueDescribe the bug
Reproduction instructions
- Download https://stackblitz.com/edit/vitejs-vite-9ibgrz (just a base Vite project with a
my-test-project
directory that has a boilerplatepackage.json
to use)- StackBlitz uses
turbo
under the hood for installing packages and I can’t figure out how to do the local linking which is essential the reproduction.yarn link
->ERR!: Unknown command 'link'
- StackBlitz uses
yarn
- Fake a
yarn add my-test-dependency
by runningcp -R my-test-dependency node_modules/my-test-dependency
yarn dev
(this will create pre-bundled dependencies formy-test-dependency
and populatenode_modules/.vite
)- Notice
my-test-dependency asdf
log in the devtools console - Get
my-test-dependency
ready for linking:cd my-test-dependency && yarn link && cd ..
- Locally link it in your project:
yarn link my-test-dependency
yarn dev
- Notice
my-test-dependency asdf
log in the devtools console - Edit
./my-test-dependency/index.js
to a differentconsole.log('other message')
just to show that Vite is pulling from the wrong spot - Notice how the log message never changes to what you set
This use-case happens when you’re doing some development on a project, find a problem in a sub-dependency, then link it locally to dive deeper.
Expected result
Vite would see that the dependency/package is now linked locally and will bust it’s own pre-bundle cache.
Workaround
- Clear your pre-bundled dependency build cache
rm -rf ./node_modules/.vite
- Notice how Vite is correctly bundling your locally linked package now and has the updated message
Dev notes
Relevant docs:
- https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
- https://vitejs.dev/guide/dep-pre-bundling.html
Reproduction
StackBlitz uses turbo
under the hood for installing packages and I can’t figure out how to do the local linking which is essential the reproduction. yarn link
-> ERR!: Unknown command 'link'
. See the reproduction steps above instead ^
System Info
vite@2.7.13
npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
npx: installed 1 in 2.131s
System:
OS: Windows 10 10.0.19044
Binaries:
Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 97.0.4692.99
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- 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 https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Dependency Pre-Bundling - Vite
Vite automatically detects dependencies that are not resolved from node_modules and treats the linked dep as source code. It will not attempt to...
Read more >Using Vite with linked dependencies - DEV Community
I start by linking my fork of Svelte and run it in dev mode so it will automatically update. # svelte-fork npm link...
Read more >How to use local Node packages as project dependencies
Test packages that have not been published to a registry, without getting caught in the pitfalls of npm and yarn's built-in solutions.
Read more >Index · Dependency scanning · Application security · User · Help ...
To identify pre-bundled dependencies, enable Container Scanning language ... To run dependency scanning jobs, by default, you need GitLab Runner with the ...
Read more >Learning the Basics - Gradle User Manual
Gradle has built-in support for dependency management and lives up to the task ... For the use case of overriding remote artifacts with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AntoineParent You need to pass the
root
from your config and have anoptimizeDeps = { exclude: [] }
object defined earlier so that it is populated. Then you pass them to your Vite config however you run it. See the Vite config docs for more details. Note that it might not solve for every case, it currently solves mine which is symlinking packages i own (usingnpm link pkg-name --save
so that they get afile:
url in the dependencies) and then having also dependencies that use the npm versions of those packages, work side-by-side, as they’ll both use their own version when they’re excluded fromoptimizeDeps
.This is the code i used to solve this in a generic way, in case it’s useful to anyone. It traverses all linked packages and finds all module specifiers and puts them in
optimizeDeps.exclude
: