React JS npm start shows failed to compile web-vitals

ssajid.ru picture ssajid.ru · Dec 21, 2020 · Viewed 7k times · Source

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;

Answer

Kelly Austin picture Kelly Austin · Feb 13, 2021

had same issues, resolved it by installing web vitals using:

npm i web-vitals --save-dev

Also deleting the whole thing and reinstalling might work but thats a longer process.