我愚蠢地使用了命令 npmauditfix --force 而不备份软件包,现在我在我的反应应用程序中发现了一些错误。
每当我启动应用程序时,我都会收到错误:
./src/reportWebVitals.js 中的错误语法错误:“导入”和“导出”可能仅出现在顶层
我该如何解决这个问题?
我的 reportWebVitals.js 文件如下所示:
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;
Run Code Online (Sandbox Code Playgroud)
我的 package.json 如下所示:
{
"name": "duran_supplements_and_workout_equipment",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000",
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"http-proxy-middleware": "^2.0.1",
"mongoose": "^5.12.13",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^0.9.5",
"socket.io-client": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": …
Run Code Online (Sandbox Code Playgroud)