未捕获的 ReferenceError:进程未定义/第 0 行:解析错误

2023-12-28

For a simple Create React App https://create-react-app.dev project, I run npm install. Then npm start opens the default web browser1. Pressing F12 displays two error messages in the console.

错误消息是:

  • Uncaught ReferenceError: process is not defined, and
  • Line 0: Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context.

我应该做什么来纠正这些错误?


我在其他地方看到过这些错误,有时指的是version中的软件包问题package.json.
请参阅下面的参考列表。 我相信参考文献3-6可能与这里的问题有关。

The .eslintrc.json and package.json files are provided below.
But since they will hardly be sufficient to reproduce the error,
here is a link to a zip file containing all the necessary project files http://user.it.uu.se/%7Ehesc0353/Q71335760.zip. 2

.eslintrc.json :

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "no-unused-vars": [
      "warn",
      {
        "argsIgnorePattern": "^_",
        "varsIgnorePattern": "^_"
      }
    ]
  }
}

package.json :

{
  "name": "Uncaught ReferenceError",
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.1",
    "@testing-library/user-event": "^7.2.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version"
    ]
  },
  "devDependencies": {
    "eslint": "^7.32.0",
    "eslint-plugin-react": "^7.29.2"
  }
}

参考

  • 创建 React 应用程序 (CRA) https://create-react-app.dev
  • 包含所需项目文件的 Zip 文件 http://user.it.uu.se/%7Ehesc0353/Q71335760.zip
  • React Uncaught ReferenceError:进程未定义 https://stackoverflow.com/q/70368760
  • 热重载时未定义进程 https://stackoverflow.com/q/70357360
  • 第 0 行:解析错误:无法读取未定义的属性“map” https://stackoverflow.com/q/62079477
  • React Typescript:第 0 行:解析错误:无法读取属性 未定义的“名称” https://stackoverflow.com/q/60729199

1 In my case Google Chrome Version 98.0.4758.102, 64-bit. Running on Windows 10.

2 Install the project (locally) by running npm install – this may take about 5-9 minutes.
Then run npm start to open the project in the default web browser.


我应该做什么来纠正这些错误?

答:全部更新npm软件包到最新版本

尝试全部更新npm包到最新版本。
目的是降低版本冲突的风险。

1.全局安装npm-check-updates

In the command line, run : 1

npm install --global npm-check-updates

2.检查是否有最新版本

Preview what packages npm-check-updates would upgrade : 2

npm-check-updates

如果该列表看起来不错,请继续将软件包更新到他们的 你的最新版本package.json :

npm-check-updates --upgrade

以下是 Windows 10 中的终端响应:

3.安装最新版本

In the command line, run: 3

npm install

4. 检查浏览器和/或终端中是否有错误

在命令行中,运行:

npm start

浏览器现在显示不少于五个错误。

终端确认了五个错误。

^ click to enlarge

哇。这看起来确实是,really很糟糕,不是吗?

Nope. Fear not! – All you need to do now is close the server (Ctrl+C) and run npm start once more.
– If you still see the errors, do it one more time – close the server and run npm start again.
If that doesn't help either, try waiting about 3-7 minutes before you try npm start again.

当我尝试此操作时,浏览器中不再出现任何错误。

终端报告了编译成功!

Yay!

参考

  • npm-check-updates– 文档 https://www.npmjs.com/package/npm-check-updates

1 I am on Windows 10, but I expect all the commands provided here to work just as fine on Linux and macOS.

2 To get a list of options, run npm-check-updates --help.

3 Expect the npm install command to take about 3-8 minutes to complete.
But if you run it again, it should complete within 10-15 seconds.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获的 ReferenceError:进程未定义/第 0 行:解析错误 的相关文章