Skip to content

Scripts: Prettier fork not found when running lint-js #21872

@renatho

Description

@renatho

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:

  1. Create a project and add the @wordpress/scripts dev dependency
> mkdir scripts-test \
&& cd scripts-test \
&& npm init -y && npm i -D @wordpress/scripts
  1. Add the script to the package.json: "lint:js": "wp-scripts lint-js"
  2. Create a js file and run the lint to see it is working.
> echo 'const x = 1;' >index.js \
&& npm run lint:js
  1. Checking the prettier dependency in this moment:
> 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]
  1. You can make a git init here and commit the package-lock to see the next changes.
  2. Remove the 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
  1. Check the prettier dependency to understand what happened (you can also see the 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):

  • A clean project with only the @wordpress/scripts installed. Reproduced in 7.1.3 and 8.0.1

Desktop (please complete the following information):

  • OS: macOS Catalina
  • NPM 6.14.4 / Node 10.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Status] BlockedUsed to indicate that a current effort isn't able to move forward[Tool] WP Scripts/packages/scripts[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions