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

import/no-extraneous-dependencies: Complains about node standard libraries #1396

Closed
burimshala-zz opened this issue Jun 25, 2019 · 20 comments
Closed

Comments

@burimshala-zz
Copy link

It throws an error which says 'path' should be listed in the project's dependencies. Run 'npm i -S path' to add it.

The eslintrc contains environment configuration:

  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },

It does not throw this error with eslint 5.x.x only with 6.x.x

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

I wonder if perhaps eslint 6 handles path differently with the node env?

Either way we should use the resolve module’s isCore method for this.

@dkrnl
Copy link

dkrnl commented Jun 26, 2019

i catch similar bug

@AlekseyLeshko
Copy link

Try set packageDir for import/no-extraneous-dependencies rule.
More info in the article
It’s work for me.

@taion
Copy link
Contributor

taion commented Jul 3, 2019

There does appear to have been a change to resolution. With ESLint v6, e.g. path now seems to resolve to path-browserify, rather than the Node built-in.

@ljharb
Copy link
Member

ljharb commented Jul 3, 2019

If so that’s a major bug; can you provide a minimal repro?

@ljharb
Copy link
Member

ljharb commented Jul 3, 2019

Also can you confirm if eslint is depending on resolve, and if so, can you try downgrading it to v1.11.0?

@taion
Copy link
Contributor

taion commented Jul 3, 2019

I don't think it's resolve or require.resolve. I think it's something specific to the webpack resolver now.

If I log the inputs to isBuiltIn in: https://github.com/benmosher/eslint-plugin-import/blob/65121104ea4659f81e8cb07184b7c1ee346a4a6f/src/core/importType.js#L25

I see e.g.

path {
  'import/resolver': { webpack: { config: [Object] }, node: { extensions: [Array] } },
  react: { pragma: 'React', version: '16.0' },
  propWrapperFunctions: [ 'forbidExtraProps', 'exact', 'Object.freeze' ],
  'import/extensions': [ '.js', '.mjs', '.jsx' ],
  'import/core-modules': [],
  'import/ignore': [ 'node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$' ]
} /Users/jjia/vendor/react-bootstrap/node_modules/path-browserify/index.js

I believe this issue comes from eslint-module-utils/resolve.

@ljharb
Copy link
Member

ljharb commented Jul 3, 2019

I mean, it makes perfect sense to me that the webpack resolver maps core modules to their respective browser shims - but i don’t know why eslint 6 would change that.

@kelchm
Copy link

kelchm commented Jul 8, 2019

I'm seeing the same issue after upgrading to eslint v6.

I can't explain why it works, but try adding this to your eslint config:

{
...
  settings: {
    'import/resolver': {
      node: {},
    },
  }
}

@MaximDevoir
Copy link

Adding onto @kelchm 's solution, node had to be the first resolver for my eslint to work.

...
  settings: {
    'import/resolver': {
      node: {}, // placed above other resolver configs
      webpack: { ... }
    }
  }
}

@taion
Copy link
Contributor

taion commented Jul 23, 2019

The above worked for me as well. We had a repo where most files ran through webpack, but a few were Node configs. Overriding those to use the node resolver fixed the issues.

As such, I don't think there was a bug here.

@ryansully
Copy link

The eslint-import-resolver-node package would need to be installed to devDependencies in your project's package.json in order to set the node property, right?

@taion
Copy link
Contributor

taion commented Jul 24, 2019

Correct.

@Xotic750
Copy link

Xotic750 commented Aug 12, 2019

If I revert back from [email protected] to @5.16.0, while leaving [email protected] then the problem goes away. Making the change #1396 (comment) with [email protected] also makes the problem go away.

Xotic750 added a commit to Xotic750/eslint-config-recommended that referenced this issue Aug 12, 2019
Update travis node versions
Work arounf for bug: import-js/eslint-plugin-import#1396
@Tecayehuatl
Copy link

Adding onto @kelchm 's solution, node had to be the first resolver for my eslint to work.

...
  settings: {
    'import/resolver': {
      node: {}, // placed above other resolver configs
      webpack: { ... }
    }
  }
}

Does any one know why this works? 🤔

@ljharb
Copy link
Member

ljharb commented Aug 27, 2019

It may be that the import/resolver setting implicitly depends on the order in which the object was defined; since object keys are conceptually unordered, and only became ordered in the spec in ES2015, it'd probably be better for this to be an array if order matters.

@brendonco
Copy link

eslint-import-resolver-node

doesnt seem to work

@ljharb
Copy link
Member

ljharb commented Jan 17, 2020

#1396 (comment) is the proper solution.

Please file a new issue if you're still having trouble with the latest release.

@ljharb ljharb closed this as completed Jan 17, 2020
aneurysmjs added a commit to aneurysmjs/react-shop that referenced this issue Nov 4, 2020
ThorgateDeveloper pushed a commit to thorgate/django-project-template that referenced this issue Mar 15, 2021
- Replace old-school stores with createSlice based ones
- HelloWorld: Use hooks instead of connect
- Post gen project: Also delete *.stories.js files when storybook is not selected
- Upgrade storybook to latest
- make storybook: Use exposed port inside container too so the link to localhost in console works
- Add fix for import-js/eslint-plugin-import#1396
- Add useEffectOnce hook from plastok

Tested both with and without storybook via a local project.

see https://thorgatedigital.atlassian.net/browse/IN-1941
ThorgateDeveloper pushed a commit to thorgate/django-project-template that referenced this issue Mar 15, 2021
- Replace old-school stores with createSlice based ones
- HelloWorld: Use hooks instead of connect
- Post gen project: Also delete *.stories.js files when storybook is not selected
- Upgrade storybook to latest
- make storybook: Use exposed port inside container too so the link to localhost in console works
- Add fix for import-js/eslint-plugin-import#1396
- Add useEffectOnce hook from plastok

Tested both with and without storybook via a local project.

see https://thorgatedigital.atlassian.net/browse/IN-1941
@AakashAlagarsamy
Copy link

AakashAlagarsamy commented Jul 9, 2021

I'm using eslint 7.29.0
Same error is showing

'webpack-merge' should be listed in the project's dependencies, not devDependencies.eslintimport/no-extraneous-dependencies
'webpack' should be listed in the project's dependencies, not devDependencies.eslintimport/no-extraneous-dependencies

My file is below

development.config.js

const { merge } = require('webpack-merge');
const webpack = require('webpack');

package.json

"devDependencies": {
    "eslint-plugin-import": "^2.23.4",
    "webpack": "^5.41.1",
    "webpack-cli": "^4.7.2",
    "webpack-dev-server": "^3.11.2",
    "webpack-merge": "^5.8.0"
  },
  "dependencies": {
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
  }

@ljharb
Copy link
Member

ljharb commented Jul 9, 2021

@AakashAlagarsamy and is your eslint configured to allow dev deps in that file?

goldentroll added a commit to goldentroll/eslint-config-airbnb that referenced this issue Mar 14, 2023
IncrePrior added a commit to IncrePrior/django-project-template that referenced this issue Nov 12, 2023
- Replace old-school stores with createSlice based ones
- HelloWorld: Use hooks instead of connect
- Post gen project: Also delete *.stories.js files when storybook is not selected
- Upgrade storybook to latest
- make storybook: Use exposed port inside container too so the link to localhost in console works
- Add fix for import-js/eslint-plugin-import#1396
- Add useEffectOnce hook from plastok

Tested both with and without storybook via a local project.

see https://thorgatedigital.atlassian.net/browse/IN-1941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests