[英]How to solve: Error in ./src/reportWebVitals.js Syntax error: 'import' and 'export' may only appear at the top level
I stupidly used the command npm audit fix --force without backing packages up and now i have caught some faults in my react app.我愚蠢地使用命令 npm audit fix --force 没有备份包,现在我在我的反应应用程序中发现了一些错误。
Whenever i start the app i get the error:每当我启动应用程序时,我都会收到错误消息:
Error in ./src/reportWebVitals.js Syntax error: 'import' and 'export' may only appear at the top level ./src/reportWebVitals.js 中的错误语法错误:'import' 和 'export' 可能只出现在顶层
How do i solve this?我该如何解决这个问题?
My reportWebVitals.js file looks like this:我的 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;
My package.json looks like this:我的 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": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
"main": "index.js",
"author": "",
"license": "ISC"
}
Apparently my react-scripts seemed to have been updated or downdated which caused the problem.显然,我的 react-scripts 似乎已经更新或过时,这导致了问题。 I used
我用了
npm uninstall react-scripts
and thereafter此后
npm install react-scripts
and my problem was solved.我的问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.