Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
usersaurus opened this issue Dec 12, 2018 · 68 comments
Closed

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

usersaurus opened this issue Dec 12, 2018 · 68 comments
Labels
locked Please open a new issue and fill out the template instead of commenting.

Comments

@usersaurus
Copy link

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.

@poub
Copy link

poub commented Jan 2, 2019

Hi,
Same error solved by remplacing the User Settings.json file in vs code. Make it basic like that

{
"terminal.integrated.fontFamily": "Fira mono for Powerline",
"window.zoomLevel": 1,
"editor.formatOnSave": true
}

@IslamWahid
Copy link

I just got the same issue

@IslamWahid
Copy link

I think it's related to eslint version as I am using this setting "prettier.eslintIntegration": true
and it's what causing the issue and this issue just happened to me after upgrading to eslint version ^5.12.0

@swansontec
Copy link

The error doesn't provide much context, so I did grep ast-utils -R node_modules/. All the hits were inside eslint, so this is almost certainly an eslint issue. I noticed that my node_modules folder had two copies of eslint, since my project depended on a different version (5.9.0) than prettier-eslint itself (^4.0.0).

Switching my project to depend on the same eslint as prettier-eslint (specifically, ^4.0.0) solved the problem for me.

@mrsufgi
Copy link

mrsufgi commented Mar 6, 2019

had the same issue, @swansontec was right, had two eslints in my node_modules

rm -rf node_modules && yarn solved my issues

@iRoachie
Copy link

Is there any resolution for this? Encountering this on eslint 5.16.0

@Calamari
Copy link

@iRoachie, have you tried rm -rf node_modules and then running npm or yarn again as @mrsufgi suggested?

@0x80
Copy link

0x80 commented Jun 24, 2019

Looks like I have the same problem. Re-installing node_modules with yarn didn't do it for me. I'm using eslint 6.0.

I am using "prettier.eslintIntegration": false for now and that works. Not sure if I need it.

@nfantone
Copy link

I think this is down to:

warning " > eslint-plugin-import@2.17.3" has incorrect peer dependency "eslint@2.x - 5.x".

Reverting to eslint 5.16.0 works for now.

@0x80
Copy link

0x80 commented Jun 24, 2019

@nfantone If I go back to 5.16.x I get errors like:

Failed to load plugin '@typescript-eslint' declared in 'CLIOptions'/myproject/src/index.ts:: Cannot find module '@typescript-eslint/eslint-plugin'
Require stack:
- /__placeholder__.js

@frederikhors
Copy link

Same problem here with eslint 6.

rm -rf node_modules and npm i did not help.

Error:

Cannot find module '../util/ast-utils'

@frederikhors
Copy link

frederikhors commented Jun 24, 2019

@CiGit this is urgent now with the new eslint 6 released.

@shaodahong
Copy link

this error happens in windows, in my mac, is fine

@frederikhors
Copy link

import-js/eslint-plugin-import#1393 is merged and release but still the same problem. This is urgent. I'm crying...

@AnathanPham
Copy link

AnathanPham commented Jun 26, 2019

The error doesn't provide much context, so I did grep ast-utils -R node_modules/. All the hits were inside eslint, so this is almost certainly an eslint issue. I noticed that my node_modules folder had two copies of eslint, since my project depended on a different version (5.9.0) than prettier-eslint itself (^4.0.0).

Switching my project to depend on the same eslint as prettier-eslint (specifically, ^4.0.0) solved the problem for me.

Your answer works

My Eslint version is 6.0.1 . It got wrong in vscode .

When I install Eslint 4.0.0 , everything was OK.

@nfantone
Copy link

@0x80 I honestly wouldn't know. You seem to be working with TS - I'm not. Most probably one of the plugins you're using do require eslint@^6.x Reverting back to latest eslint@5.x worked for me.

@nfantone
Copy link

this error happens in windows, in my mac, is fine

@shaodahong Not actually true, I'm afraid. It fails on macOS as well. AFAIK, this is tied to supporting latest eslint. It happens regardless of which OS you are on.

@shaodahong
Copy link

@nfantone sounds bad, hope there fix it

@bradennapier
Copy link

bradennapier commented Jun 27, 2019

Just ran into this as well so I assume this is about to really hit the fan if not updated soon since I just went through updating eslint across our repos. Luckily google gets here as the top result so it wasn't a time consuming thing to troubleshoot.

Note that with the issue that @0x80 ran into you simply need to reload the VSCode Window (Cmd + Shift + P --> Reload Window)

@samrith-s
Copy link

samrith-s commented Jun 27, 2019

None of the mentioned solutions do the trick for me.

With eslint@6.0.1 it couldn't read any plugin, got the error @0x80 mentioned.

With eslint@5.16.0 it couldn't find ast-utils, got the error @frederikhors

@nfantone
Copy link

I've managed to get this working again with latest eslint-config-prettier released some hours ago. Here's what I have:

"eslint": "^6.0.1"
"eslint-config-prettier": "^6.0.0"
"eslint-plugin-import": "^2.18.0"
"eslint-plugin-node": "^9.1.0"
"eslint-plugin-prettier": "^3.1.0"
"eslint-plugin-promise": "^4.2.1"
"prettier": "^1.18.2"

@samrith-s
Copy link

I am not using eslint-plugin-node and eslint-plugin-promise, but everything else is the same version:

{
    "eslint": "^6.0.1",
     "eslint-config-prettier": "^6.0.0",
     "eslint-plugin-import": "^2.18.0",
     "eslint-plugin-prettier": "^3.1.0",
}

Still doesn't work.

6/27/2019, 5:43:41 PM:
----------------------
Failed to load plugin 'prettier' declared in 'CLIOptions'/Users/samrith/Work/totem/serverless-graphql/src/handler.js:: Cannot find module 'eslint-plugin-prettier'
Require stack:
- /__placeholder__.js

Setting prettier.eslintIntegration to false works for now.

@nfantone
Copy link

nfantone commented Jun 27, 2019

@samrith-s That looks like an entirely different error to me: Cannot find module 'eslint-plugin-prettier'. I've never seen that one.

Sorry for the brainless question, but are you sure it's declared and installed on serverless-graphql?

@samrith-s
Copy link

samrith-s commented Jun 27, 2019

I'm positive.
image
This is my go-to setup. I've used it in 50+ projects and it has always worked. Somehow, every single project broke in the last 3-4 days.

@nfantone
Copy link

@samrith-s Apart from the obvious stuff (try removing the lockfile, rm -rf node_modules/ and yarn or npm i, again), I cannot think of a reason why it wouldn't work for you.

prettier is working as expected in all the projects I've updated so far.

@0x80
Copy link

0x80 commented Jun 27, 2019

@nfantone I've upgraded all my dependencies to latest, removed node_modules and yarn.lock and reinstalled + restarted vscode.

Still the same ast-utils error for me. This is with versions:

    "eslint": "^6.0.1",
    "eslint-config-prettier": "^6.0.0",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-react": "^7.14.2",
    "prettier": "^1.18.2",

@samrith-s
Copy link

@nfantone I’ve tried all the possible solutions out there. The only thing that works is disabling prettier.eslintIntegration. I’m almost positive this is an error in prettier-vscode while using enabling ESLint integration.

@donniean
Copy link

@nfantone I’ve tried all the possible solutions out there. The only thing that works is disabling prettier.eslintIntegration. I’m almost positive this is an error in prettier-vscode while using enabling ESLint integration.

the same.

#863

@0x80
Copy link

0x80 commented Jul 14, 2019

@dijam @adriangrahl Is VSCode called MSCode now? Did I miss the memo?

@mikemak-es
Copy link

I'm still getting this issue despite following @dijam comment.

my versions and settings are below:

System:
macOS: 10.14.5
Node: 12.6.0
VSCode: 1.36.1

Project Package.json:
"eslint-plugin-react": "^7.14.2",
"eslint": "^5.16.0",
"prettier": "^1.17.0",

VSCode setting:
prettier.eslintIntegration: true

@nvtuan305
Copy link

Downgrade eslint to previous working version not helped. I'm getting this issue.

@kamos1
Copy link

kamos1 commented Jul 18, 2019

I did a global uninstall and a local uninstall then reinstalled everything locally and now things are working.

    "eslint": "^6.0.1",
    "eslint-config-prettier": "^6.0.0",
    "eslint-plugin-import": "^2.18.0",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.14.2",
    "eslint-plugin-react-hooks": "^1.6.1",
    "prettier": "^1.18.2"

@Carrie999
Copy link

for vscode how to handle ?

@Carrie999
Copy link

delete eslint Getting better

@nvtuan305
Copy link

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
Copy link

YIREN1 commented Jul 20, 2019

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
Copy link

jimblue commented Jul 20, 2019

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
Copy link

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
Copy link
Member

ntotten commented Aug 12, 2019

Duplicate of #870

@ntotten ntotten marked this as a duplicate of #870 Aug 12, 2019
@ntotten ntotten closed this as completed Aug 12, 2019
@Mr-SPM
Copy link

Mr-SPM commented Aug 14, 2019

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
Copy link

please help

@zfeher
Copy link

zfeher commented Aug 17, 2019

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
Copy link

Upgrading eslint from 6.1.0 to 6.2.0 fixed the problem for me

@samrith-s
Copy link

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

@eouw0o83hf
Copy link

eouw0o83hf commented Aug 28, 2019

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

muffinista added a commit to muffinista/before-dawn that referenced this issue Aug 28, 2019
ESLint is failing in windows for some reason. This version seems to work.

@see prettier/prettier-vscode#672
@Rennzie

This comment has been minimized.

@mort3za
Copy link

mort3za commented Sep 12, 2019

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
Copy link

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
Copy link

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
Copy link

akmur commented Feb 6, 2020

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

@ntotten
Copy link
Member

ntotten commented Feb 10, 2020

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
Copy link

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.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label May 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests