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

Error: Cannot find module 'prettier' with @wordpress/eslint-plugin v3.4.0 #20027

Closed
kasparsd opened this issue Feb 4, 2020 · 7 comments · Fixed by #20028
Closed

Error: Cannot find module 'prettier' with @wordpress/eslint-plugin v3.4.0 #20027

kasparsd opened this issue Feb 4, 2020 · 7 comments · Fixed by #20028

Comments

@kasparsd
Copy link
Contributor

kasparsd commented Feb 4, 2020

Describe the bug

See this example repository with the minimum setup to replicate the issue:
https://github.com/kasparsd/wordpress-eslint-plugin-prettier

Running eslint with .estlintrc.js config set to:

{
	"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
}

and @wordpress/eslint-plugin as a development dependency set to version ^3.4.0 produces the following error:

Error: Cannot find module 'prettier'
Occurred while linting /Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/src/script.js:1
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Program (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:162:26)
    at listeners.(anonymous function).forEach.listener (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/kaspars/Projects/wp-scripts-eslint-prettier-bug/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @kasparsd/[email protected] lint: `eslint ./src`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the @kasparsd/[email protected] lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/kaspars/.npm/_logs/2020-02-04T10_54_35_609Z-debug.log

See the output on Travis:
https://travis-ci.com/kasparsd/wp-scripts-eslint-prettier-bug/jobs/283358536#L519-L538

Downgrading @wordpress/eslint-plugin to version 3.3.0 fixes the problem -- see this pull request:

kasparsd/wordpress-eslint-plugin-prettier#1

and the Travis CI output for the change:

https://travis-ci.com/kasparsd/wp-scripts-eslint-prettier-bug/jobs/283361201#L463-L467

To reproduce

Steps to reproduce the behavior:

  1. Clone the sample repository git clone https://github.com/kasparsd/wordpress-eslint-plugin-prettier
  2. Run npm install
  3. Run npm run lint

Expected behavior

eslint runs as expected.

Desktop (please complete the following information):

  • macOS 10.15.3
  • Terminal
  • node v8.17.0, npm 6.13.6.
@kasparsd
Copy link
Contributor Author

kasparsd commented Feb 4, 2020

Could this be related to #18048 #19963?

@ntwb
Copy link
Member

ntwb commented Feb 4, 2020

p.s Thanks for the contribution and bonus points for the demo repo, thanks 💯

@marekdedic
Copy link
Contributor

Hi, I'm seeing the issue again with version 4.0.0

@gziolo
Copy link
Member

gziolo commented Feb 10, 2020

Hi, I'm seeing the issue again with version 4.0.0

Prettier is now listed as the dependency of @wordpress/eslint-plugin. Are you using npm 6.9.0 or later?

https://unpkg.com/browse/@wordpress/[email protected]/package.json

@marekdedic
Copy link
Contributor

Hi,
I am a bit confused now... The CI for updating the package from 3.4.1 to 4.0.0 failed:

https://circleci.com/gh/skaut/skaut-google-drive-gallery/3451

and when I SSH into it, I can confirm npm is on version 6.13.4. When I do npm install it says

npm WARN [email protected] requires a peer of prettier@>= 1.13.0 but none is installed. You must install peer dependencies yourself.

npm update doesn't do anything.

However, locally, everything runs OK on the same branch.... Any ideas?

@ocean90
Copy link
Member

ocean90 commented Feb 14, 2020

I was still getting this error when @wordpress/babel-preset-default was also added in devDependencies.

  "devDependencies": {
    "@wordpress/babel-preset-default": "^4.10.0",
    "@wordpress/scripts": "^7.1.0"
  }

Removing @wordpress/babel-preset-default fixed the issue for me. Also had to delete node_modules first because npm i only returned

npm WARN [email protected] requires a peer of prettier@>= 1.13.0 but none is installed. You must install peer dependencies yourself.

@marekdedic
Copy link
Contributor

I can confirm that purging node_modules worked for me. Didn't realize they were cached by the CI...

My mistake, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants