prettier-vscode: Cannot find module '../ast-utils' when formating

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 68
  • Comments: 68 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Same problem here with eslint 6.

rm -rf node_modules and npm i did not help.

Error:

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

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.

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 }

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.

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

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

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

@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.

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

rm -rf node_modules && yarn solved my issues

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

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 !

delete eslint Getting better

I have to downgrade eslint version because the issue. I hope the solution will come.

Enabling prettier.eslintIntegration makes VSCode use prettier-eslint, instead of prettier binary. Which is something I’m not doing. This might be it, then. And there’s actually no real need for using prettier-eslint if you configure your lint rules appropriately.

Yes, but it’s strange that it’s been working with that enabled for so long now, and suddenly in the last 3-4 days, it breaks.

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.

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

Updating MSCode to 1.36.0 fixed the issue for me too.

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.

please help

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.

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 !!!

I had similar problem for a while. I did everything possible. Downgrading and use fix versions. Even copy-paste from other folders/projects that work but didn’t work. Tried empty project with exact packages and it worked but when implement the same in my current project it wouldn’t. But, when Code released the new version, all went back to normal 😃 I assume MSCode was using some packages that messed up my configs that technically should have the highest priority when loading eslint config. Anyway, All good and I can work again 😃 My current versions: "eslint": "^5.16.0","prettier": "^1.17.0", MSCode version: 1.36.0

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

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)

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

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

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

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 😄 😄 😄

@EthanNYT

Then I’d need an ESLint config file and a Prettier config file, right?

No, not really. There are eslint-plugin-prettier and eslint-config-prettier that handle that for you. And prettier doesn’t even need one (defaults work well enough). Although, there’s nothing preventing you from configuring them separately.

And have to make sure any changes you make to one you have to make to the other, etc.

Plugins above, if kept up to date, will make sure changes in prettier don’t mess up with eslint rules and viceversa. And on that same note, once you settle on a set of rules that makes sense for you (or your organisation), you very rarely modify them, in my experience. And not entirely sure what that “etc.” would encompass. There’s honestly nothing else to it.

Also, it seems that ESLint has many settings that are missing from Prettier.

Those would still apply and won’t conflict with each other. What would the issue be here?

Here’s my typical eslint + prettier configuration for node projects (I like to use standard + semicolon).

// package.json
{
    "eslint": "^6.0.1",
    "eslint-config-prettier": "^6.0.0",
    "eslint-config-standard": "^12.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",
    "eslint-plugin-standard": "^4.0.0",
    "prettier": "^1.18.2"
}
// .eslintrc.json
{
  "extends": [
    "standard",
    "prettier/standard",
    "plugin:prettier/recommended"
  ],
  "parserOptions": {
    "sourceType": "script"
  },
  "env": {
    "node": true,
    "jest": true
  },
  "rules": {
    "semi": [
      2,
      "always"
    ],
    "no-extra-semi": 2,
    "strict": [
      "error",
      "global"
    ]
  }
}
// .prettierrc (can be omitted completely if you're fine with defaults)
{
  "singleQuote": true,
  "printWidth": 100
}

That’s all you need. No prettier-eslint, at all.

But, anyway, I’d ditch prettier-eslint entirely. Doesn’t have much use other than facilitating initial setup

Then I’d need an ESLint config file and a Prettier config file, right? And have to make sure any changes you make to one you have to make to the other, etc.

Also, it seems that ESLint has many settings that are missing from Prettier.

Another thing I noticed, if you have installed latest version of Node (mine is 12.4.0), it breaks.

@samrith-s I was actually going to ask you this (check the “Edit” history on my previous comment!). I’m on LTS.

❯ node -v
v10.16.0

But, anyway, I’d ditch prettier-eslint entirely. Doesn’t have much use other than facilitating initial setup - which, if you have been working on 50+ projects in the past like it was mentioned, should not pose a problem.

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.

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

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"

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

Yep, ditching it entirely from now on, so that no such problem occurs. Thanks a lot @nfantone for that comment, helped me debug in that direction! 😁

@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",

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.

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"

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