question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

peerDepdencies of a used package not considered

See original GitHub issue

Bug Description

A package that’s only in peerDependencies of a used package is still marked as unused even though it really is used.

Code snippets

Where the dependency is used:

const jsdomGlobal = require('jsdom-global');

Where the dependency is listed in package.json:

{
  "name": "test_depcheck",
  "license": "PUBLIC DOMAIN",
  "dependencies": {
    "jsdom": "~11.11.0",
    "jsdom-global": "~3.0.2"
  }
}

Versions

  • node -v: v10.15.2
  • npm -v: 6.4.1
  • depcheck --version: 0.7.2

Extra info

If you remove jsdom from package.json, then yarn install gives the following error and the code doesn’t work:

yarn install v1.13.0
warning package.json: License should be a valid SPDX license expression
warning test_depcheck: License should be a valid SPDX license expression
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > jsdom-global@3.0.2" has unmet peer dependency "jsdom@>=10.0.0".
[4/4] 🔨  Building fresh packages...

success Saved lockfile.
✨  Done in 0.70s.

json output:

{"dependencies":[],"devDependencies":[],"missing":{},"using":{"jsdom-global":["/Users/dlj/temp/index.js"],"jsdom":["/Users/dlj/temp/index.js"]},"invalidFiles":{},"invalidDirs":{}}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
rumplcommented, Apr 6, 2021

@robross0606 could you open a new issue and provide a repository reproducing this error please?

0reactions
robross0606commented, Apr 5, 2021

This still appears to be a problem. My project has a peer dependency on prom-client:

npm WARN prometheus-gc-stats@0.5.1 requires a peer of prom-client@>= 10 < 12 but none is installed. You must install peer dependencies yourself.

However, depcheck lists it as unused after installation:

C:\Code\code>depcheck --version
1.4.0

C:\Code\code>depcheck
Unused dependencies
* prom-client
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Peer Dependencies in JavaScript
Peer dependencies really come into play when you're developing code that will be used by others, such as plugins and packages.
Read more >
Should I duplicate "peerDependencies" in "dependencies ...
So while installing packages using npm install , NPM will attempt to install an optional dependency too. But if it isn't able to...
Read more >
npm Peer Dependencies - JavaScript inDepth
Peer Dependencies are used to specify that our package is compatible with a specific version of an npm package. Good examples are Angular...
Read more >
npm Peer Dependencies - Fathom
Peer Dependencies. If you've used nodejs at all, you will have come across normal dependencies in package.json. They are used to describe the...
Read more >
Difference between dependencies, devDependencies and ...
peerDependencies are not automatically installed. You need to manually modify your package.json file in order to add a Peer Dependency.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found