By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – How to get prettier errors in terminal when starting react app?
JavaScript

Javascript – How to get prettier errors in terminal when starting react app?

Admin
Last updated: 2023/12/14 at 4:00 AM
Admin
Share
3 Min Read
How to get prettier errors in terminal when starting react app?

Problem:

Disclaimer, I am not using eslint-plugin-prettier, I do not want to run it as a linting task, I want linting and formatting to stay separated. Plus it affects the performance of these steps a little.

Contents
Problem:Solution:

I am wondering, how to get prettier formatting warnings/errors as I get when using eslint. When eslint finds and issue, the build from create-react-app shows me the errors in my terminal. Prettier does not.

What I tried was:

"start:dev": "yarn start & yarn prettier-watch",
"prettier-watch": "onchange \"**/*\" -- prettier --check --config .prettierrc.json --ignore-unknown {{changed}}"

The prettier-watch script works if I run it manually, but it doesn’t work when I let the start script run it. What happens is that the output from prettier shows for a split second and then disappears when the build is done.

Reason why I am doing this: other collaborators might not do auto-formatting using their editor, and I don’t want to show errors everywhere in the IDE, just a kind reminder in the terminal that what they changed could/should be formatted with prettier. I am also adding this check as a step in the CI pipeline.

I wonder how eslint is configured to integrate with the build of create-react-app and output those errors, would be helpful.

Solution:

I wouldn’t use the single ampersand to run the two commands in parallel, as it requires UNIX-like environment (not specified in the question, but being Node.js not UNIX-specific I can assume there may be Windows-based collaborators). Also pay attention that NPM, Yarn and similar tools may try to mitigate the differences between shells by allowing only a subset of operators.

There are many npm packages that tackles this issue, e.g.:

  • npm-run-all with the --parallel option (or shortly as run-p):
    "start:dev": "npm-run-all --parallel start prettier-watch",
    

    Note that, despite the name, it supports yarn correctly;

  • concurrently:
    "start:dev": "concurrently \"yarn:start\" \"yarn:prettier-watch\""
    

    or with explicit command

    "start:dev": "concurrently \"yarn start\" \"yarn run prettier-watch\""
    

    Note that the double quotes (that needs to be escaped) are required.

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article custom cursor img not dissapearing outside of box on mouseleave event Javascript – custom cursor img not dissapearing outside of box on mouseleave event
Next Article How to detect and map many keys being pressed at once Javascript – How to detect and map many keys being pressed at once
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?