prettier / prettier-vscode

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

Cannot find module '../ast-utils' when formating #672

Closed usersaurus closed 4 years ago

usersaurus commented 5 years ago

Hi all,

I'm getting the following error after installing prettier-vscode and trying to format a file.

Cannot find module '../ast-utils'

I have no idea about what's happening.

nvtuan305 commented 4 years ago

At the current, my working solution is disable ESlint Integration setting in vscode while waiting for new update version.

[1] Turn off ESlint Integration setting in vscode

[2] Install eslint, eslint-config-google (I'm using config from Google)

     npm i --save-dev eslint eslint-config-google

The newest version will be:

    "eslint": "^6.0.1",
    "eslint-config-google": "^0.13.0"

[3] Configure eslint and prettier to make it work as expected

.eslintrc.json

{
  "extends": ["google"],
  "parserOptions": {
    "ecmaVersion": 2017
  },
  "rules": {
    "object-curly-spacing": ["error", "always"],
    "max-len": ["error", 80],
    "indent": [2, 2, {"SwitchCase": 1}]
  }
}

.prettierrc

{
  "semi": true,
  "trailingComma": "es5",
  "singleQuote": true,
  "printWidth": 80,
  "arrowParens": "always"
}

With this configuration, I got the result as expected before getting error 😄 😄 😄

YIREN1 commented 4 years ago

on
eslint "^5.16.0", "prettier": "^1.18.2"

And it works for me if I delete all modules about eslint and reinstall them

jimblue commented 4 years ago

This issue isn't the real issue, this is just a consequence. The real problem come from prettier-vscode compatibility with ESlint 6... This topics is becoming a mess a bit more each day and it should be close in favor of #870 !

douglas-cavalcante commented 4 years ago

eslint: yarn add eslint-plugin-react eslint-plugin-react-native eslint-config-airbnb eslint@^4.19.1 eslint-plugin-import eslint-plugin-jsx-a11y -D

eslint+prettier: yarn add prettier eslint-config-prettier eslint-plugin-prettier babel-eslint -D

ntotten commented 4 years ago

Duplicate of #870

Mr-SPM commented 4 years ago

Also, there is another thing a little strange. Before I went back to 5.16.0, I try to downgrade eslint version...like 5.14.0, then 5.12.0, and then 5.8.0. Finally 5.4.0 works well. But when I tried to upgrade, even 5.14.0 can work. Every time I changed the version, I reloaded vscode and make sure that there were no copied versions in node_modules. But back to 6.0.1 error of this issue occured. Then 5.16.0, another error. But after I remove one of the rules (just I mentioned above). Every thing went well. I don't even know whether the same problem will occur again tomorrow...QAQ

downgrade 5.4.0 . it works !!!

toastyboost commented 4 years ago

please help

zfeher commented 4 years ago

Downgrading to 5.4.0 helped made it work. After that doing a couple of upgrades: to 5.14.0, 5.15.3 and eventually to 5.16.0 all started to work again for some reason \o/ Thank you @Mr-SPM for this tip.

Before that I tried to remove all eslint dependencies and reinstall them, it didn't work. Tried the rm -rf node_modules && npm i treatment, it didn't work. Strange beast, hope it stays working.

VahanAper commented 4 years ago

Upgrading eslint from 6.1.0 to 6.2.0 fixed the problem for me

samrith-s commented 4 years ago

Neither ESLint 5.16 or ^6 works. Only 5.4 works for me. For 6.x, there's this error https://github.com/microsoft/vscode-eslint/issues/696

eouw0o83hf commented 4 years ago

Just so it shows back up at the bottom of the thread: pinning to eslint version ^5.4 fixes this.

yarn upgrade eslint@^5.4
Rennzie commented 4 years ago

Incase this is still an issue, I found that changing

"prettier.eslintIntegration": true

to

"prettier-eslint.eslintIntegration": true

in Settings (JSON) for VS Code fixed all the issues with prettier and eslint. I've managed to upgrade to the latest version of prettier and eslint and things are working as expected.

mort3za commented 4 years ago

Seems "prettier.eslintIntegration" config is now deprecated. there are a deprecation notice and solution in the readme: https://github.com/prettier/prettier-vscode#vscode-eslint-and-tslint-integration

EthanNYT commented 4 years ago

Thanks @mort3za . For the lazy:

Use prettier-eslint instead of prettier. Other settings will only be fallbacks in case they could not be inferred from ESLint rules.

This formats your code via prettier, and then passes the result of that to eslint --fix. This way you can get the benefits of prettier's superior formatting capabilities, but also benefit from the configuration capabilities of eslint.

madflanderz commented 4 years ago

I had the same weird problem. I use eslint with eslint-plugin-prettier together. Somehow this was colliding with VSCode prettier plugin. After i disabled VSCode prettier plugin and using only eslint it was working again. Also had to set "eslint.autoFixOnSave" to true.

akmur commented 4 years ago

For some reason removing the vs code prettier plugin worked for me

ntotten commented 4 years ago

If you are using ESLint to do formatting, another option instead of disabling the plugin would be to disable prettier from formatting the languages you want to be handled by ESLint. You can do this with the by adding a .vscode/settings.json file to your project with the following content:

{
    "prettier.disableLanguages": ["js"]
}
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.