Describe the bug
Error with the prettier dependency while running the lint script from @wordpress/scripts after a new npm install.
To reproduce
Steps to reproduce the behavior:
@wordpress/scripts dev dependency> mkdir scripts-test \
&& cd scripts-test \
&& npm init -y && npm i -D @wordpress/scripts
"lint:js": "wp-scripts lint-js"> echo 'const x = 1;' >index.js \
&& npm run lint:js
> npm ls prettier
[email protected] /Users/renatho/Downloads/scripts-test
βββ¬ @wordpress/[email protected]
βββ¬ @wordpress/[email protected]
β βββ prettier@npm:[email protected] deduped
βββ prettier@npm:[email protected]
git init here and commit the package-lock to see the next changes.node_modules folder, reinstall the packages and run the lint script. The new install will update (unexpectedly) our package-lock.json and It stops to work because it doesn't find the prettier. You will see the error Error: Cannot find module 'prettier'> rm -rf node_modules \
&& npm i \
&& npm run lint:js
package-lock diff):> npm ls prettier
[email protected] /Users/renatho/Downloads/scripts-test
βββ¬ @wordpress/[email protected]
βββ¬ @wordpress/[email protected]
β βββ UNMET PEER DEPENDENCY prettier@npm:[email protected]
βββ prettier@npm:[email protected]
Expected behavior
Install the @wordpress/scripts and after other npm install it continues to work properly while running the npm run lint:js.
Version (please complete the following information):
@wordpress/scripts installed. Reproduced in 7.1.3 and 8.0.1Desktop (please complete the following information):
Itβs a know issue and I donβt think we can help much about it. In my experience running npm install twice resolves it, so it looks like there is something weird happening on the npm side when using aliases. There are two things that might help:
npm i again when it happens or installing the aliased Prettier fork as a dependency of the project Thank you for your answer with the suggestions @gziolo !!
For now, what we are using as a workaround is to install the prettier fork as a direct dependency. :)
And I tested running the npm i again, but it didn't solve for me :(
For me, after the error happens changing the package-lock, it doesn't work more unless we remove the package-lock to reinstall.
@renatho thanks for testing and sharing what works for you π
I just ran into this randomly as well. I had been using the lint command with no issues for awhile, and then all the sudden I got the error. If you remove package-lock.json file, delete the node_modules folder and then run npm i again, the error went away for me.