prettier-vscode: Failed to load 'react-hooks'

Failed to format React files

I’m using VSCode - insiders and Remote - SSH to develop on a remote machine. When using create-react-app, Prettiers fails to format the files and gives an error.

Steps To Reproduce:

  1. Create React app with npx create-react-app app
  2. Configure ESLint and Prettier extensions in VSCode
  3. Save file

Expected result

Formatted file.

Actual result

Error by Prettier:

8/16/2019, 9:45:43 AM:
----------------------
Failed to load plugin 'react-hooks' declared in 'CLIOptions'/home/shaunjanssens/projects/gotoo/webapp/src/App.js:: Cannot find module 'eslint-plugin-react-hooks'
Require stack:
- /home/shaunjanssens/__placeholder__.js

Additional information

VS Code Version: 1.38.0-insider

Prettier & Prettier Plugin Version: 1.18.2 (installed on server) / 1.9.0

OS and version: Mac OS and Ubuntu 18.04 (remote development)

React-scripts: 3.1.1

settings.json

{
  "eslint.validate": [
    {
      "language": "vue",
      "autoFix": true
    },
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "javascript",
      "autoFix": true
    },
    {
      "language": "react",
      "autoFix": true
    }
  ],
  "eslint.autoFixOnSave": true,
  "editor.formatOnPaste": true,
  "editor.formatOnSave": true,
  "editor.formatOnType": false,
  "prettier.eslintIntegration": true,
  "prettier.singleQuote": true,
  "prettier.semi": false
}

I already tried to install eslint-plugin-react-hooks both as a dev dependency and global on server.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 31
  • Comments: 38 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I resolve this problem use "prettier.eslintIntegration": false in my VSCode config

prettier.eslintIntegration is deprecated so I removed it from my VSCode settings

According to Prettier’s documentation it’s recommended to use the ESLint or TSLint extensions directly so I just use "eslint.autoFixOnSave": true in my VSCode config and it is working well.

Changed prettier.eslintIntegration": true to "prettier-eslint.eslintIntegration": true in settings.json

In my case ES lint was installed globally so I resolved it by installing the ‘eslint-plugin-react-hooks’ package globally.

This is the ES lint error report

This can happen for a couple of reasons:

  1. The plugin name is spelled incorrectly in an ESLint configuration file (e.g. .eslintrc).
  2. If ESLint is installed globally, then make sure ‘eslint-plugin-react-hooks’ is installed globally as well.
  3. If ESLint is installed locally, then ‘eslint-plugin-react-hooks’ isn’t installed correctly.

https://github.com/facebook/react/issues/16531#issuecomment-523620795

rm -rf node_modules && npm i and then restart vscode fixed it for me.

@diljitvj Thanks ! Installed the ‘eslint-plugin-react-hooks’ globally with

npm i -g eslint-plugin-react-hooks

and everything is back to normal 💪

A temporary I did was to remove the eslintConfig in my package.json

"eslintConfig": {
     "extends": "react-app"
   },

Changed prettier.eslintIntegration": true to "prettier-eslint.eslintIntegration": true in settings.json @nick-gaudreau When I set that in settings.json => Unknown Configuration Setting => Not working!

Thanks, @izayl. I fixed this issue like you

RIP productivity and sanity at work this week. Hope someone finds a proper fix