prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.39k stars 255 forks source link

Failed to load config "prettier" to extend from? #211

Closed luskin closed 2 years ago

luskin commented 2 years ago

Our builds are failing on Netlify with the error:

Error:

12:58:57 PM: $ react-scripts build
12:59:00 PM: Creating an optimized production build...
1:04:01 PM: Failed to compile.
1:04:01 PM: 
1:04:01 PM: Failed to load config "prettier" to extend from.
1:04:01 PM: Referenced from: /opt/build/repo/.eslintrc.js

eslintrc.js:

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: ['plugin:react/recommended', 'prettier'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 12,
    sourceType: 'module',
  },
  plugins: ['react', 'react-hooks', '@typescript-eslint', 'prettier'],
  rules: {
    'react/prop-types': 'off',
    'react/display-name': 'off',
    semi: 'off',
    'no-undef': 'off',
    'react/react-in-jsx-scope': 'off',
    'prettier/prettier': 'warn',
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
}

devDependencies:

...
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.23.2",
    "eslint-plugin-react-hooks": "^4.2.0",
    "prettier": "^2.4.1"
...

We have been trying a variety of things but can't seem to get past this hurdle.

lydell commented 2 years ago

Hi!

It looks like you have configured things correctly, and have all you need in package.json.

Can you make a minimal reproduction? Without that I can’t think of anything that could help you. That’s usually a good way of finding the problem yourself, btw!

lydell commented 2 years ago

Closing because no response.

cherewaty commented 2 years ago

@luskin I ran into a similar issue.

If your NODE_ENV is production, your devDependencies (including eslint-config-prettier) might not have been installed.

One of the quirks of react-scripts's "you only need to install one package" approach is that eslint and eslint-config-react-app are installed as dependencies.

react-scripts build will try to run eslint; if your eslint config only extends or includes plugins that are in react-scripts' dependencies, it'll work just fine.

But once you add eslint-config-prettier as a dev dependency, it won't be installed in a production environment, and react-scripts build will fail eslint checks.

One approach is to move eslint-config-prettier to dependencies, but that blurs the lines between dependencies and devDependencies.

My workaround was to disable the eslint check in production. I added a .env.production that contains DISABLE_ESLINT_PLUGIN=true: https://create-react-app.dev/docs/advanced-configuration/. I have a separate CI step that runs eslint by itself, so I don't also need react-scripts build to run that check.

evy0311 commented 2 years ago

Just commenting to thank @cherewaty for their response above! We were running into this exact same problem, and adding in the environment variable to disable the ESLint portion of create-react-app solved our issue. Thanks so much!!

richardloveday commented 1 year ago

Thanks so much @cherewaty was stumped by this until we saw your reponse!