javascript - eslint not ignoring node_modules and getting error when try to lint - Stack Overflow

admin2025-04-20  0

I'm trying to implement eslint in a Next.js project.The file structure look like below

.eslintignore
.eslintrc.js
.next
.prettierrc
.stylelintrc.js
ponents
forms
modals
modules
node_modules

And I have node_modules/* in my .eslintignore file. When I try to lint these by eslint --fix /sources/**/*.js I am getting below error

You are linting "/sources/node_modules/ally.js", but all of the files matching the glob pattern "/sources/node_modules/ally.js" are ignored.

Anyone can help me to solve this? Thanks

I'm trying to implement eslint in a Next.js project.The file structure look like below

.eslintignore
.eslintrc.js
.next
.prettierrc
.stylelintrc.js
ponents
forms
modals
modules
node_modules

And I have node_modules/* in my .eslintignore file. When I try to lint these by eslint --fix /sources/**/*.js I am getting below error

You are linting "/sources/node_modules/ally.js", but all of the files matching the glob pattern "/sources/node_modules/ally.js" are ignored.

Anyone can help me to solve this? Thanks

Share Improve this question asked May 20, 2021 at 6:14 RichRich 1952 gold badges8 silver badges29 bronze badges 10
  • Did you try **/node_modules/*? – Manuel Spigolon Commented May 20, 2021 at 6:37
  • Yes. But gives the same error. – Rich Commented May 20, 2021 at 6:39
  • try ./node_modules – enoch Commented May 20, 2021 at 6:44
  • @enoch no use. Same error. – Rich Commented May 20, 2021 at 6:45
  • try to delete node_modules and .next folder then reinstall with them with npm install. – enoch Commented May 20, 2021 at 6:49
 |  Show 5 more ments

3 Answers 3

Reset to default 2

The issue might e from your mand line.

If you forget the single quotes, your terminal is going to evaluate the glob (**/*), not eslint. So this will skip all eslint ignore settings.

If you enable eslint's debug logs with --debug, you will see it in action:

  • Without single quotes:
$ eslint **/*.ts --debug 2>&1 | grep "CLI args"

eslint:cli CLI args: [ 'a.ts', 'b.ts', 'node_modules/package/a.ts', 'node_modules/package/b.ts', '--debug' ]
  • With single quotes:
$ eslint '**/*.ts' --debug 2>&1 | grep "CLI args"

eslint:cli CLI args: [ '**/*.ts', '--debug' ]

If .eslintignore located in the same directory as node_modules you can specify it as node_modules.

# .eslintignore
node_modules
**/.next/**
**/_next/**
**/dist/**

.eslintignore follows .gitignore syntax. See .gitignore specs for more details.

Linters don't work the same with different node versions.

In this case updating node from v14.x to v16.x worked for me.


If .eslintignore config doesn't work for you, consider checking your node version.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745106286a285308.html

最新回复(0)