-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Scripts: Prettier fork not found when running lint-js #21872
Comments
It’s a know issue and I don’t think we can help much about it. In my experience running
|
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 |
@renatho thanks for testing and sharing what works for you 👍 |
* switch to using wp-env instead of wordpress/scripts for setting up local environment * fix js code style * remove unused install-wp script * use wp-env in travis build * add missing env variables * add aliased wp-prettier as direct dependency (see: WordPress/gutenberg#21872) * fix broken theme activation after installation * use chmod command from gutenberg repository in travis ci * fix theme on test instance * temporary disable broken alignment tests * fix js code style * skip tests with skip function * use install wordpress flag from gutenberg * update composer dependencies * fix plugin folder name in ci build * disable alignment tests * use correct phpunit script in ci
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 |
The best way to address this issue would be to stop using a npm alias for Prettier fork and use the official Prettier. However we would have to change WordPress coding styles for JavaScript to reflect how Prettier removes spaces around brackets. |
I imagine it would have a big impact. But it can be a good option for those who want to avoid this issue by replacing this standard, installing the dependency directly in their projects. :) |
It only seems like a big impact on the vast majority of projects. If you don't have hundreds of open PRs in the repository then it all boils down to running |
They have it installed in the top-level Gutenberg does it, too. This resolves the issue but it shouldn't be necessary if one of the sub packages does it already. Another workaround is to run |
I'm pretty sure this is a bug in npm 6.x.x. The A year ago, I was solving another npm bug where packages were mistakenly removed from the Apparently the code for package aliases has a similar bug. My impression is that the support for package aliases was added to npm as a quick-and-dirty patch and is not very reliable. Running Upgrade to npm 7 will solve this hopefully. |
It would be awesome. Regardless, I plan to recommend that WordPress projects switch to the official Prettier and adjust coding style guidelines to align with what Prettier can support. |
@gziolo that would be fantastic. It would make things so much easier… this bug has been persistently annoying 😅 |
My proposal needs to wait until we sort out how we want to use TypeScript in Gutenberg: |
The same issue was reported in #34622. The context was |
I created this test repository https://github.com/xwp/gutenberg-issue-21872-scripts which attempts to isolate the issue and require just The results are all over the place as it appears to be an issue with Node and/or npm instead of these packages. |
@kasparsd, thank you for doing a very in-depth investigation. That was my understanding, too. That's why I proposed we stop using the aliased fork and go with the official Prettier to save folks from all the hassle that it creates, even if that is independent from the WordPress packages. |
* Update @wordpress/scripts * Update 01-basic-esnext to use block.json * Add .nvmrc file. * Add .editorconfig file. * Add dependencies and package-json.lock * Add common eslintrc file. * Remove js map files * Ignore dev js mapping files. * Update main package.json to use latest version of the @wordpress/scripts package. * Split out files and linting fixes. * Inline comments to explain the loading process. * Add build files. * Add manual linting to avoid error with prettier not being found. * Remove linting from ci due error with prettier not being found. See WordPress/gutenberg#21872 * Remove npm test command in CI * Add node 14 to versions in CI
I opened #37607 to start making the official proposal to switch to the original Prettier in the most recent 2.5 version. |
* Update @wordpress/scripts * Update 01-basic-esnext to use block.json * Add .nvmrc file. * Add .editorconfig file. * Add dependencies and package-json.lock * Add common eslintrc file. * Remove js map files * Ignore dev js mapping files. * Update main package.json to use latest version of the @wordpress/scripts package. * Split out files and linting fixes. * Inline comments to explain the loading process. * Add build files. * Add manual linting to avoid error with prettier not being found. * Remove linting from ci due error with prettier not being found. See WordPress/gutenberg#21872 * Remove npm test command in CI * Add node 14 to versions in CI
Describe the bug
Error with the
prettier
dependency while running the lint script from@wordpress/scripts
after a newnpm install
.To reproduce
Steps to reproduce the behavior:
@wordpress/scripts
dev dependency"lint:js": "wp-scripts lint-js"
git init
here and commit thepackage-lock
to see the next changes.node_modules
folder, reinstall the packages and run the lint script. The new install will update (unexpectedly) ourpackage-lock.json
and It stops to work because it doesn't find theprettier
. You will see the errorError: Cannot find module 'prettier'
package-lock
diff):Expected behavior
Install the
@wordpress/scripts
and after othernpm install
it continues to work properly while running thenpm run lint:js
.Version (please complete the following information):
@wordpress/scripts
installed. Reproduced in7.1.3
and8.0.1
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: