【问题标题】:Why I can build my react app but cannot start it为什么我可以构建我的 react 应用程序但无法启动它
【发布时间】:2021-10-24 12:07:10
【问题描述】:

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
  • 纱线:v1.22.11
  • nodejs: v16.6.2

【问题讨论】:

    标签: node.js reactjs yarnpkg


    【解决方案1】:

    如果我不得不猜测,我会说 REMOVE node_modules & package-lock.json 或 yarn.lock THEN yarn AGAIN。

    有时升级模块会导致未知错误。

    【讨论】:

    • 我第一次尝试,但它不起作用?。
    • 哦不,如果问题仍然困扰着您并且没有人给出正确的答案。也许你应该尝试在rehype-katex 中打开一个问题
    【解决方案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"
        ]
    

    然后重新编译你的项目。

    【讨论】:

    • 非常感谢您的解决方案,我已经通过迁移到 next.js 解决了(?)这个问题。?
    【解决方案3】:

    我遇到了同样的错误,而且我花了比我愿意承认的时间更长的时间来找到它的原因。对我来说,它是数字文字中的下划线。

    num = 2_000; // bad bad not good
    num = 2000; // no probs
    

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 1970-01-01
      • 2011-01-14
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      相关资源
      最近更新 更多