eslint-plugin-prettier: Failed to load plugin 'prettier' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-prettier'

What version of eslint are you using? “eslint”: “^7.21.0”,

What version of prettier are you using? “prettier”: “^2.2.1”,

What version of eslint-plugin-prettier are you using? “eslint-plugin-prettier”: “^3.3.1”

Please paste any applicable config files that you’re using (e.g. .prettierrc or .eslintrc files)

module.exports = {
  root: true,
  env: {
    browser: true,
    es6: true,
    node: true,
  },
  extends: [ "plugin:prettier/recommended" ],
  parserOptions: {
    parser: "babel-eslint",
    ecmaVersion: 12,
    sourceType: "module"
  },
  rules: {
    "no-console": 0
  },
  globals: {
    getApp: false,
    Page: false,
    wx: false,
    App: false,
    getCurrentPages: false,
    Component: false
  }
}

What did you expect to happen?

[Error] 
Failed to load plugin 'prettier' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-prettier'
Require stack:
- /Users/xxx/Documents/xxxx/xxxx/__placeholder__.js
Referenced from: /Users/xxx/Documents/xxxx/xxxxx/.eslintrc.js
Happened while validating /Users/xxxxx/Documents/xxxxx/xxxxx/xxxxx.js
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-prettier' is installed globally as well.
3. If ESLint is installed locally, then 'eslint-plugin-prettier' isn't installed correctly.

Consider running eslint --debug /Users/xxxxx/Documents/xxxxx/xxxxx/xxxxx.js from a terminal to obtain a trace about the configuration files used.

What actually happened? normal work

devDependencies version

  "devDependencies": {
    "autoprefixer": "^9.7.3",
    "babel-eslint": "^10.1.0",
    "del": "^6.0.0",
    "eslint": "^7.21.0",
    "eslint-config-prettier": "^8.1.0",
    "eslint-plugin-prettier": "^3.3.1",
    "gulp": "^4.0.2",
    "gulp-imagemin": "^7.1.0",
    "gulp-notify": "^3.2.0",
    "gulp-plumber": "^1.2.1",
    "gulp-postcss": "^9.0.0",
    "gulp-rename": "^2.0.0",
    "gulp-replace": "^1.0.0",
    "gulp-sass": "^4.1.0",
    "gulp-tap": "^2.0.0",
    "miniprogram-automator": "^0.10.0",
    "path": "^0.12.7",
    "postcss": "^8.2.1",
    "prettier": "^2.2.1",
    "yargs": "^16.2.0"
  }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 40
  • Comments: 37 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Running npm i eslint-plugin-prettier@latest -D solved this for me.

@jamesgordo I was able to get it working the other day. I just wiped out node_modules and did a fresh npm i. It still wasn’t working, but after I restarted VSCode, it did 🤷

For me in vscode I pressed F1 then typed reload window and the error was gone.

still, I can’t fix the issue with these solutions

I have the same issue as @nickzelei – shared company config – that suddenly started being unable to find eslint-plugin-prettier. This only happens in CI, not in local dev environment.

I moved eslint-plugin-prettier from dev dependencies into dependencies, and it works now.

We are experiencing this as well. We have a node module which requires eslint-plugin-prettier as a dependency and in all our projects it installs eslint-plugin-prettier directly in node_modules (in that case everything works fine), but in one project it installs it in node_modules/OUR_NODE_MODULE/node_modules (in this case it doesn’t work). In both cases, our node module is the only one which requires eslint-plugin-prettier, yarn why eslint-plugin-prettier also outputs the same information (only our node module). I figured out that installing https://www.npmjs.com/package/@nuxtjs/storybook causes eslint-plugin-prettier to be installed node_modules/OUR_NODE_MODULE/node_modules, but it is still the only eslint-plugin-prettier being installed and I have no clue why @nuxtjs/storybook would cause that.

However, this seems to be a bug (I think) in yarn v1 as this only happens with yarn v1. This does not happen with yarn v3 anymore (I would assume it also works with yarn v2). As yarn v1 is not updated anymore (except for critical vulnerabilities), you might want to upgrade to yarn v3 (if possible for you).

I’ve had the same problem with eslint@8.x.x and eslint-config-prettier@8.x.x . After downgrading

npm i -D eslint@^7 eslint-config-prettier@^7

things started to work again.

Restarting WebStorm was sufficient for me

We are running into the same issue. We are using yarn 1.22 during local development and npm 6.13.17 centrally. We are experiencing this issue “Failed to load plugin ‘<name>’ declared in ‘.eslintrc’: Cannot find module '<eslint-plugin-name>” for multiple plug-ins:

Tried using:

So I think this is still a problem and somehow the resolution does not work correctly. Based on the various pages and issues describing the same problem again and again with various versions - I don’t think it’s a problem specific to a specific version but rather a general problem in some environments on how e.g. the node_modules are loaded and organized.

I had a similar problem with my monorepo. Moving the eslint-plugin-prettier and prettier dependencies from a subproject to the yarn workspace dependencies did the trick.

Deleting node_modules, reopening the VS Code and running yarn install helped me.

you need wiped out node_modules .cache. I am facing the same issue.

@git-ashish the only thing that worked in CI was adding eslint-plugin-prettier as a top-level dependency in package.json, even though it shouldn’t need to be added as it’s already a dependency of our organization’s eslint-config package,

I’ve been struggling to find a fix for this one for several days already and finally made it work on my end.

It seems that even if I run npm install or npm i eslint-plugin-prettier@latest -D , the eslint-plugin-prettier folder is not created in the node_modules directory. Based from my observation, some dev dependency packages are not installed if NODE_ENV=production

Try checking the NODE_ENV value of your machine by running echo $NODE_ENV . if the current value is production try changing the values to development by running export NODE_ENV=development .

After changing the values, try running npm install again and check if the plugin is installed and folder exists: ls -lah node_modules/eslint-plugin-prettier

If the folder exists, try running npm run build if it works.

Hope this can help.

For me this error resolved when i update my node version to v18.11.0 and npm -v is 8.19.2

Thanks! I’ll give that a go. For th time being I used just _npm ci _ and that worked

@git-ashish no, this was happening only on my mac and not on my linux dev-box, so I run this only on linux now.

I have the same issue as @nickzelei – shared company config – that suddenly started being unable to find eslint-plugin-prettier. This only happens in CI, not in local dev environment.

Did you find a solution for CI @okize?

@baxelson12 Thanks for the response, but I already have the latest version (4.0.0) installed. Just to be sure, I uninstalled the plugin and reinstalled it using that command, but I’m still receiving the same error in VSCode.