Eslint cannot read config file
Asked Answered
P

2

25

I am setting up my first eslint. For some reason in other computers it works except on mine ..

Im using VScode

As soon as I open my editor I get the following message: Cannot read config file: /Users/user/Documents/repos/project/C:/mydirectory/.eslintrc.json Error: ENOENT: no such file or directory, open Source: ESLint (Extension)

.eslintrc.json is on my root directory.

This is my config file:

{
    "parser": "babel-eslint",
    "extends": "airbnb",
    "env": {
      "browser": true,
      "jest": true
    },
    "rules": {
      "quote-props": [2, "as-needed"],
      "comma-dangle": "error",
      "no-console": ["warn", { "allow": ["warn", "error"] }],
      "no-debugger": "error",
      "react/prop-types": 0,
      "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
      "object-curly-newline": ["error", { "multiline": true }],
      "no-underscore-dangle": 0,
      "jsx-a11y/click-events-have-key-events": 0,
      "jsx-a11y/anchor-is-valid": 0,
      "no-await-in-loop": 0,
      "no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }],
      "arrow-parens": ["error", "as-needed"],
      "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
      "import/prefer-default-export": 0,
      "react/no-find-dom-node": 0,
      "no-shadow": 0,
      "max-len": 0,
      "consistent-return": 0,
      "no-plusplus": 0,
      "spaced-comment": 0,
      "react/react-in-jsx-scope": 0,
      "react/jsx-filename-extension": 0,
      "indent": ["error", 4],
      "react/jsx-indent": ["error", 4],
      "react/jsx-indent-props": ["error", 4]
    }
  }

This is my package.json

{
  "name": "project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@internal/project": "latest",
    "@rematch/core": "^0.6.0",
    "ag-grid": "^18.1.1",
    "ag-grid-react": "^18.1.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.5",
    "babel-jest": "^23.4.0",
    "babel-loader": "^7.1.5",
    "babel-plugin-transform-decorators": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-preset-react-app": "^3.1.2",
    "babel-runtime": "^6.26.0",
    "classnames": "^2.2.6",
    "css-loader": "^1.0.0",
    "dotenv": "^6.0.0",
    "dotenv-expand": "^4.2.0",
    "eslint": "^5.1.0",
    "eslint-config-react-app": "^2.1.0",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-flowtype": "^2.50.0",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-jsx-a11y": "^6.1.0",
    "eslint-plugin-react": "^7.10.0",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.2",
    "jest": "^23.4.0",
    "lodash": "^4.17.10",
    "object-assign": "^4.1.1",
    "promise": "^8.0.1",
    "prop-types": "^15.6.2",
    "react": "^16.4.1",
    "react-apollo": "^2.1.9",
    "react-dom": "^16.4.1",
    "react-jss": "^8.6.1",
    "react-loadable": "^5.4.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "lint": "eslint --ext .js --ext .jsx src",
    "eject": "react-scripts eject"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,mjs}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node",
      "mjs"
    ]
  },
  "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-decorators-legacy"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "devDependencies": {
    "eslint-config-airbnb": "^17.0.0"
  }
}

I've tried several things, including: adding { "root": true }, opening from project, installing/uninstalling eslint extension

Philip answered 31/7, 2018 at 15:51 Comment(7)
It looks like the path your editor is expecting is wrong. What is the editor you are using, and in what way have you configured it?Alb
Your path doesn't look quite right, I don't think it should have C: in thereKelcie
What do you mean by "in your root directory"? In any case, sounds like your editor config is wrong, but you don't say anything about what editor you're using, so shrug. In general they'll look for .eslint in the directory you open it from.Lettered
Thank you for your input. I am using VsCode, I just updated my post. @DaveNewton. In my settings.json my { eslint.options} is set to an empty object. Should it be configured there?Philip
@SteveVaughan, can you elaborate on what you mean by how I configured it?Philip
@rowmna Sure, so in VSCode, you may well need to provide it a path to the config file. The error you have is very likely caused by using the default setup mentioned here: marketplace.visualstudio.com/… Try and setting that to the absolute path to your config fileAlb
@SteveVaughan that worked, thanks! If you want you can add a post and i'll give you an upvote :)Philip
A
4

It looks like this relates to VSCode, the configuration file should be setup with a path to your config. See the guide here

The eslintOptions.configFile should be an absolute path to your config file.

Alb answered 31/7, 2018 at 17:2 Comment(1)
I work on my project mostly in WebStorm and this problem appears to have occurred after working on it a bit in VSCode -- it may have also made a difference that I opened one of the subfolders and not the project's root folder. I can't figure out how to fix it and I don't see eslintOptions even in the vscode settings json. Any ideas?Suppressive
N
12

Just restarting the ESlint server fixed the problem for me.

Normandnormandy answered 9/11, 2021 at 6:50 Comment(4)
You can restart the ESLint Server in VS Code with Ctrl + P --> ESLint: Restart ESLint ServerAlgonkian
@Rubanov I think Ctrl + Shift + P would be the correct shortcut though. (Cmd + Shift + P on macOS)Normandnormandy
you are correct. It's Ctrl + Shift + PAlgonkian
I totally agree. But it worked in my case unfortunately.Normandnormandy
A
4

It looks like this relates to VSCode, the configuration file should be setup with a path to your config. See the guide here

The eslintOptions.configFile should be an absolute path to your config file.

Alb answered 31/7, 2018 at 17:2 Comment(1)
I work on my project mostly in WebStorm and this problem appears to have occurred after working on it a bit in VSCode -- it may have also made a difference that I opened one of the subfolders and not the project's root folder. I can't figure out how to fix it and I don't see eslintOptions even in the vscode settings json. Any ideas?Suppressive

© 2022 - 2024 — McMap. All rights reserved.