Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make npm install package and ignore one (or all) peer dependencies?

I have [email protected] installed. I want to install vuex-module-decorators@latest, which has a peerDependency of vuex 3 (not >=3). I have a feeling this will work fine with vuex 4. Is there a way for me to tell npm to install this new package, without crashing due to not being able to resolve the peer dependency (since 4 != 3)? Or do I need to just create my own fork of vuex-module-decorators with an updated package.json that allows vuex >=3?

like image 573
Christopher Shroba Avatar asked Sep 03 '25 03:09

Christopher Shroba


2 Answers

Fast but potentially unsafe: Using --legacy-peer-deps will usually allow you to install the package without meeting the peer dependency requirements. (This was the default using npm@6 so I assume you are using npm@7 or later if you are seeing a problem.) If that doesn't work, --force will install without regard to peer dependencies.

Requires slightly more effort but is more safe/surgical: Use npm overrides. These were introduced in npm 8.x.

like image 76
Trott Avatar answered Sep 07 '25 17:09

Trott


You should use overrides with modern versions of npm, since --legacy-peer-deps is less safe and could silence other legacy peer dependencies that you may want to fix:

"overrides": {
  "vuex-module-decorators": {
    "vuex": "$vuex",
  }
}
like image 34
Nick McCurdy Avatar answered Sep 07 '25 17:09

Nick McCurdy