prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

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

Open usersaurus opened this issue 7 years ago • 68 comments

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.

usersaurus avatar Dec 12 '18 11:12 usersaurus

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 }

poub avatar Jan 02 '19 22:01 poub

I just got the same issue

IslamWahid avatar Jan 11 '19 04:01 IslamWahid

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

IslamWahid avatar Jan 11 '19 04:01 IslamWahid

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.

swansontec avatar Jan 30 '19 23:01 swansontec

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

rm -rf node_modules && yarn solved my issues

mrsufgi avatar Mar 06 '19 13:03 mrsufgi

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

iRoachie avatar Jun 24 '19 02:06 iRoachie

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

Calamari avatar Jun 24 '19 09:06 Calamari

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.

0x80 avatar Jun 24 '19 11:06 0x80

I think this is down to:

warning " > [email protected]" has incorrect peer dependency "[email protected] - 5.x".

Reverting to eslint 5.16.0 works for now.

nfantone avatar Jun 24 '19 12:06 nfantone

@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

0x80 avatar Jun 24 '19 14:06 0x80

Same problem here with eslint 6.

rm -rf node_modules and npm i did not help.

Error:

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

frederikhors avatar Jun 24 '19 19:06 frederikhors

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

frederikhors avatar Jun 24 '19 19:06 frederikhors

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

shaodahong avatar Jun 25 '19 13:06 shaodahong

https://github.com/benmosher/eslint-plugin-import/pull/1393 is merged and release but still the same problem. This is urgent. I'm crying...

frederikhors avatar Jun 25 '19 19:06 frederikhors

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.

AnathanPham avatar Jun 26 '19 01:06 AnathanPham

@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 [email protected] worked for me.

nfantone avatar Jun 26 '19 11:06 nfantone

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.

nfantone avatar Jun 26 '19 11:06 nfantone

@nfantone sounds bad, hope there fix it

shaodahong avatar Jun 27 '19 02:06 shaodahong

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)

bradennapier avatar Jun 27 '19 03:06 bradennapier

None of the mentioned solutions do the trick for me.

With [email protected] it couldn't read any plugin, got the error @0x80 mentioned.

With [email protected] it couldn't find ast-utils, got the error @frederikhors

samrith-s avatar Jun 27 '19 14:06 samrith-s