为什么我可以构建我的react应用程序,但不能启动它



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

我也犯过同样的错误,我花了比我愿意承认的更长的时间才找到原因。对我来说,它是数字字面量中的下划线。

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

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

直接去包装。项目根目录下的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"
]

然后重新编译项目。

在更新后出现了同样的问题,数字中的下划线分隔符引发了同样的错误("模块解析失败:标识符直接在数字"之后)。

这是由于Babel,这个问题是通过添加@babel/plugin-proposal-numeric-separator插件解决的。

如果我不得不猜测,我会说REMOVE node_modules &package-lock。Json或yarn。再锁住纱线

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

相关内容

最新更新