no-extraneous-dependencies doesn't support nested package.json

See original GitHub issue

Example of my project structure:

├── package.json
├── src
│   ├── components
│   │   ├── Avatar
│   │   │   ├── Avatar.css
│   │   │   ├── Avatar.js
│   │   │   ├── README.md
│   │   │   └── package.json
│   │   ├── Button
│   │   │   ├── Button.css
│   │   │   ├── Button.js
│   │   │   ├── ButtonSpinner.css
│   │   │   ├── ButtonSpinner.js
│   │   │   ├── README.md
│   │   │   └── package.json

Root package.json contains all dependencies, nested package.json looks like this:

{
  "name": "Avatar",
  "main": "Avatar.js"
}

That’s why I got wrong warnings:

src/components/Avatar/Avatar.js
  1:1  error  'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it            import/no-extraneous-dependencies
  2:1  error  'classnames' should be listed in the project's dependencies. Run 'npm i -S classnames' to add it  import/no-extraneous-dependencies

Is this fixable?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:40
  • Comments:51 (13 by maintainers)

github_iconTop GitHub Comments

25reactions
jacobraskcommented, May 27, 2019

When trying to pass a function to the rule with both eslint 5.16.0 and 6.0.0-alpha I get

	Configuration for rule "import/no-extraneous-dependencies" is invalid:
	Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '[Function: import/no-extraneous-dependencies]').
24reactions
miguelollercommented, Sep 12, 2016

Expanding on my previous comment, here’s what my ESLint settings look like:

'import/resolver': {
  node: {
    moduleDirectory: [
      'node_modules',
      './src',
    ],
  },
},

Inside src I have 3 main folders: services, components, and scenes (this is for a large React Native app, by the way). Each of those main folders contains a package.json that looks like this (each with their respective names):

{
  "name": "services"
}

Elsewhere in my project I can now import a component (or a service or a scene) by simply typing:

import Button from 'components/Button'

This is much more manageable than typing something like:

import Button from '../../../../../../../../components/Button';

Currently, I get import/no-extraneous-dependencies: 'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it because the minimal package.json doesn’t have dependencies and the rule doesn’t care to look up higher in the directory tree.

If the rule allowed me to do the following, it would solve this issue:

'import/no-extraneous-dependencies': {
  moduleDirectories: ['./'] // or any other configuration that's most convenient for all
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

no-extraneous-dependencies doesn't support nested package ...
I use package.json instead of index.js . I'm not used to monorepos. I'm too. It's not monorepo.
Read more >
Why (and How Can I FIx) ESLint import/no-extraneous ...
As far as I can tell, there is no issue with your package.json, ... -plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md.
Read more >
npm-prune
Description. This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed....
Read more >
eslint/eslint - Gitter
I understand babel-eslint is by design more loose so as to support experimental ... Run 'npm i -S assert' to add it import/no-extraneous-dependencies....
Read more >
@lingui/macro - Reference — LinguiJS documentation
It's recommended to install @lingui/macro package as a production dependency rather than development one to avoid import/no-extraneous-dependencies errors ...
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