prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

Failed to load 'react-hooks' #910

Closed shaunjanssens closed 4 years ago

shaunjanssens commented 4 years ago

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.

danikkks commented 4 years ago

same problem

xinkule commented 4 years ago

same here

I guess the problem lies on the eslint version 6.x, it's incompatible with the current version of prettier-vscode.

danihazler commented 4 years ago

same problem here

jaegz commented 4 years ago

Also experiencing this issue

rrlevy commented 4 years ago

Same problem here

gregkonush commented 4 years ago

also experiencing this problem:

cemujax commented 4 years ago

Same problem here

YYvanYang commented 4 years ago

Same problem here

windows 10 64bit vscode 1.37.1 CRA 3.1.0

agusterodin commented 4 years ago

Must be a vscode issue

eclecticjohny commented 4 years ago

Same as @cemujax here

lsw8168 commented 4 years ago

same problem

windows 10 create-react-app v3.1.1 vscode version 1.37.1

WeiShengv99 commented 4 years ago

prettier 1.9.0 vscode 1.37.1 eslint-plugin-vue and eslint last version

I get Similar problem i got the error of 'Failed to load plugin 'vue' declared in........cant get module eslint-plugin-vue' but i already install it both as a dev dependency and global dependency.

tylergraf commented 4 years ago

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

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

yogathanh99 commented 4 years ago

@tylergraf I do like you talk but I can't fix this issue

deadcoder0904 commented 4 years ago

Yep facing same issue

tim-sheung commented 4 years ago

same

Jonny15t commented 4 years ago

I was able to correct this issue by deleting eslint-config-react-app from node_modules and reinstalling the newest version via npm i --save-dev eslint-config-react-app.

OS: Windows 10 CRA: v3.1.1 VSCode: v1.37.1

izayl commented 4 years ago

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

yogathanh99 commented 4 years ago

Thanks, @izayl. I fixed this issue like you

agusterodin commented 4 years ago

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

ntotten commented 4 years ago

Duplicate of #870

cburkins commented 4 years ago

Also disabled Prettier ESLint integration to fix the issue. When I disabled it (vis User Settings panel), it was marked as deprecated in orange text. Now when I go back to look at it, I'm pretty sure the setting is no longer there. Did a bit of reading on this as well: https://github.com/prettier/prettier-vscode#vscode-eslint-and-tslint-integration

agusterodin commented 4 years ago

Yeah I just narrowed down through trial and error that prettier eslint will not work on any project with react-scripts later than 3.0.1

Pretty devastating considering my entire workflow revolves around using this. So painful developing without it. I could imagine a lot of other people work this way as well.

opolancoh commented 4 years ago

I think it's a problem generating the template with NPX when you execute npx create-react-app app. If you use create-react-app app the problem doesn't occurs.

dvj1988 commented 4 years ago

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.
KasparasGud commented 4 years ago

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

npm i -g eslint-plugin-react-hooks

and everything is back to normal 💪

nick-gaudreau commented 4 years ago

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

harrytran998 commented 4 years ago

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!

harrytran998 commented 4 years ago

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.

It worked! Thanks @diljitvj

eltNEG commented 4 years ago

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

"eslintConfig": {
     "extends": "react-app"
   },
thealexandrelara commented 4 years ago

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.

tupizz commented 4 years ago

Here too... Any workaround?

dvj1988 commented 4 years ago

@tupizz Try this => https://github.com/prettier/prettier-vscode/issues/910#issuecomment-525174068

neyosoft commented 4 years ago

lint.autoFixOnSave":

This setting works for me. There is an update on prettier website also about the deprecation and changes. Besides that, I installed 'eslint-plugin-react-hooks' globally.

floroz commented 4 years ago

here as well, I solved it by installing the 'eslint-plugin-react-hooks' npm package locally as dev dependency "eslintConfig": { "extends": "react-app", "plugins": [ "react-hooks" ] },

skube commented 4 years ago

@floroz That didn't seem to work for me :(

floroz commented 4 years ago

@floroz That didn't seem to work for me :(

I have gone through several steps:

  1. Remove all eslint and prettier global npm packages
  2. Remove all local eslint and prettier packages and plugins
  3. Remove VS Code Extensions ESLint and Prettier
  4. Reinstall VS Code ESLint extensions
  5. If you are using Create-React-App look at the 'Output' for extensions error
  6. Gradually install each package and monitor errors in the output.
github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.