node.js - 为什么我可以构建我的 React 应用程序但无法启动它

标签 node.js reactjs yarnpkg

rehype-katex5.0.0 升级到 6.0.1 后,当我运行 yarn start ,我得到了:

./node_modules/hast-util-to-text/index.js 363:65
Module parse failed: Identifier directly after number (363:65)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|     //     break is the zero-width space character (U+200B), then the break is
|     //     removed, leaving behind the zero-width space.
>     if (lines[index].charCodeAt(lines[index].length - 1) === 0x20_0b
|     /* ZWSP */
|     || index < lines.length - 1 && lines[index + 1].charCodeAt(0) === 0x20_0b

但它在 codesandbox 中工作正常, yarn build 也可以。我该如何解决这个问题?

我的 package.json:

{
  "name": "blog",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "@testing-library/user-event": "^13.2.1",
    "gh-pages": "^3.2.3",
    "pubsub-js": "^1.9.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-helmet": "^6.1.0",
    "react-markdown": "^7.0.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "react-syntax-highlighter": "^15.4.4",
    "rehype-katex": "^6.0.1", // Upgrade
    "rehype-raw": "^6.0.0",
    "remark-gfm": "^2.0.0",
    "remark-math": "^5.0.0",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "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"
    ]
  },
  "homepage": "https://xxx.github.io"
}
  • 操作系统:Linux
  • yarn :v1.22.11
  • nodejs: v16.6.2

最佳答案

我遇到了完全相同的问题,并通过以下 SO POST 解决了这个问题:https://stackoverflow.com/a/67574280/16766691

只需转到项目根文件夹下的 package.json,

替换

"browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

  "browserslist": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ]

然后重新编译你的项目。

关于node.js - 为什么我可以构建我的 React 应用程序但无法启动它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68904475/

相关文章:

node.js - 通过命令行传递时,node-gyp 变量的行为有所不同

javascript - Phantom.js : Use locally, npm已安装,jquery

windows - 如何在react中使用h5p?

node.js - npm 安装较新版本的对等依赖项

javascript - NTLM 身份验证后站点的 NodeJs 身份验证

node.js - 为什么 Node JS 会阻塞异步文件操作?

javascript - 在 ReactJS 中操作 DOM 是好习惯吗?

ruby-on-rails - yarn install --check-files 给了我我不明白的错误输出

javascript - 如何让 cordova 使用 yarn js 而不是 npm 来添加插件

node.js - 部署后 Heroku 的应用程序错误