Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React JS npm start shows failed to compile web-vitals

I'm getting the error:

failed to compile -/src/reportWebVitals.js Module not found: Can't resolve 'web-vitals'. Since new to react JS, could not find what happened. Here is the reportWebVitals.JS file. Thanks in advance for the help. "/src/reportWebVitals.js Module not found: Can't resolve 'web-vitals' in 'E:\ReactResources\RectProjects\test-app\src'"

const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
  getCLS(onPerfEntry);
  getFID(onPerfEntry);
  getFCP(onPerfEntry);
  getLCP(onPerfEntry);
  getTTFB(onPerfEntry);
});
}};
export default reportWebVitals;
like image 879
ssajid.ru Avatar asked Dec 21 '20 16:12

ssajid.ru


People also ask

Can't resolve Web Vitals create React app?

To solve the error "Module not found: Error: Can't resolve 'web-vitals'", make sure to install the web-vitals package by opening your terminal in your project's root directory and running the command npm install --save-dev web-vitals and restart your development server.

What is Web vitals in React JS?

The goal of Web Vitals is to provide clear guidance on what metrics matter and how to measure them. The idea behind Web Vitals is that we can measure them on real users interacting with the page. The results can vary based on the network conditions or the device's capabilities.

Can I delete Report Web vitals?

js and reportWebVitals. js may be deleted as they are not needed in our application right now. Then, for some reason you are using a React version older than the current version 18. You quite likely need to do the same for your other projects.

What is ENV D TS React?

The react-app-env. d. ts references the types of react-scripts , and helps with things like allowing for SVG imports.


3 Answers

You need to install web vitals. Open your terminal and run the following command:

npm i web-vitals --save-dev

Also, deleting the whole thing and reinstalling might work, but that's a longer process.

like image 198
Kelly Austin Avatar answered Oct 06 '22 22:10

Kelly Austin


For anyone coming here from starting a brand new app with create-react-app: If you are using npm but run create-react-app without explicitly specifying it, it will use yarn when available. I was able to bypass this issue by adding the flag --use-npm.

So, for example:

npx create-react-app my-app --use-npm

Source

like image 34
Alvaro Avatar answered Oct 07 '22 00:10

Alvaro


Delete all the files & Folders inside test-app folder. Reinstall all the packages now and start npm. It will work.

like image 1
passionFinder Avatar answered Oct 07 '22 00:10

passionFinder