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

peerDepdencies of a used package not considered #341

Closed
daveisfera opened this issue Apr 22, 2019 · 12 comments
Closed

peerDepdencies of a used package not considered #341

daveisfera opened this issue Apr 22, 2019 · 12 comments

Comments

@daveisfera
Copy link

daveisfera commented Apr 22, 2019

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":{}}
@rumpl
Copy link
Member

rumpl commented Apr 22, 2019

Hey, I see that you created a test module, could you push it on github please?

You talk about devDependencies but in your package.json your deps are in dependencies, also I'm not sure which one is marked as unused, is it jsdom or jsdom-global?

@daveisfera daveisfera changed the title devDepdencies of a used package not considered peerDepdencies of a used package not considered Apr 22, 2019
@daveisfera
Copy link
Author

There's not anything more to add then what I included in the bug and I just realized that I had a typo in the original submission. I meant to write peerDependencies and accidentally wrote devDependencies. Here's the link to the code that's "causing the problem":
https://github.com/rstacruz/jsdom-global/blob/371c36a2b64a7c2d014260212cc1a22a6bd1de2b/package.json#L24

@rumpl
Copy link
Member

rumpl commented Apr 22, 2019

Understood, thanks for reporting this, we don’t look at peer dependencies, we should I guess

@rumpl
Copy link
Member

rumpl commented May 12, 2019

I'm going to close this one since we already support and have a test for peer dependencies.

If you still have problems please open a new issue with a reproducible repo.

Thanks

@rumpl rumpl closed this as completed May 12, 2019
@dave-nm
Copy link

dave-nm commented May 12, 2019

The file in the original comment reproduces the issue.

rumpl added a commit that referenced this issue May 12, 2019
Testing peer dependencies for #341
@rumpl
Copy link
Member

rumpl commented May 12, 2019

@dave-nm I just made a test with jsdom and jsdom-global (see here), could you take a look and tell me if this is what you have? The test passes, jsdom is found as a dependency. There must be something else that is blocking depcheck. I am going to need you to tell me more about your setup if you want me to help you.

Cheers.

@rumpl rumpl reopened this May 12, 2019
@rumpl
Copy link
Member

rumpl commented May 12, 2019

Keep in mind that, in order for peer dependencies to work, you need to do a npm install (or yarn or whatever).

If there are no node_modules where depcheck can read your depency package.json then depcheck can't read and check your peer dependencies.

@daveisfera
Copy link
Author

You're right. The issue was that my node_modules wasn't up to date and so the necessary peerDependencies info wasn't there.

@rumpl
Copy link
Member

rumpl commented May 14, 2019

Nice!

Thanks for updating the issue ^^

@daveisfera
Copy link
Author

I just realized what the actual problem is. We're using yarn workspaces, so the package.json of the peer dependency is in the node_modules in the parent directory and depcheck isn't loading that info and that's why it's warning about an unused dependency that really is used.

@robross0606
Copy link

robross0606 commented 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

@rumpl
Copy link
Member

rumpl commented Apr 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants