简体   繁体   English

如何解决:./src/reportWebVitals.js 语法错误:'import'和'export'可能只出现在顶层

[英]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.

相关问题 错误:ENOENT:没有那个文件或目录,打开 C:\\myangularproject\\src\\node_modules\\nlcst-pattern-match\\lib\\index.js - Error: ENOENT: no such file or directory, open C:\myangularproject\src\node_modules\nlcst-pattern-match\lib\index.js 谁知道如何解决 npm start error: Error: assets.flatMap is not a function - Anyone knows how to solve npm start error: Error: assets.flatMap is not a function 错误:您可能需要合适的加载程序来处理此文件类型 - Error: You may need an appropriate loader to handle this file type 部署到 heroku 时如何解决 Node 和 reactapp 错误? - How to solve Node and reactapp error when deploying to heroku? 由于降低了依赖性,因此出现了与模块相关的新类型错误 - New type of module related error appear since downgrading dependency JSX标签处的语法错误 - Syntax error at JSX tag 如何在没有配置文件的情况下修复导入/导出babel-eslint? - How to fix import/export babel-eslint without configuration file? gulp-babel插件错误:不允许插件/预设文件导出对象,仅导出功能 - Error in plugin gulp-babel: Plugin/Preset files are not allowed to export objects, only functions 构建因语法错误而失败 - 微匹配 - Build is failing for Syntax Error - Micromatch 错误:找不到模块'/app/app,js' heroku - error: Cannot find module '/app/app,js' heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM