【问题标题】:NPM - Website built using React does not buildNPM - 使用 React 构建的网站无法构建
【发布时间】:2020-12-12 17:14:36
【问题描述】:

我已经使用 ReactJS 创建了一个网站,并且在我的本地机器上运行良好。 但是当我运行npm run build 时,这是我得到的错误:

> react-snap

�  pageerror at /personal-site/: SyntaxError: Unexpected token '<'

✅  crawled 1 out of 1 (/personal-site/)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! personal-site@2.1.0 postbuild: `react-snap`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the personal-site@2.1.0 postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\[MYUSERNAMEHERE]\AppData\Roaming\npm-cache\_logs\2020-08-24T04_04_29_334Z-debug.log

我打算将它部署到 github 页面。在我的 package.json 中,我有以下行作为主页:

"name": "personal-site",
"version": "2.1.0",
"homepage": "https://[MYUSERNAME].github.io/personal-site/",

请注意,personal-site 是我的项目和存储库的名称。我还有一个.env 文件,如下所示:

NODE_ENV=production

PORT=7999
BASE_PATH=/personal-site/

这个错误的原因是什么?另外,我该如何克服这个错误?

以下是调试日志。 [修剪]

...
24 verbose node v12.18.1
25 verbose npm  v6.14.5
26 error code ELIFECYCLE
27 error errno 1
28 error personal-site@2.1.0 postbuild: `react-snap`
28 error Exit status 1
29 error Failed at the personal-site@2.1.0 postbuild script.
29 error This is probably not a problem with npm. There is likely additional logging output above.
30 verbose exit [ 1, true ]

【问题讨论】:

  • 调试日志中有什么?
  • @rayhatfield 请检查更新!谢谢!
  • react-snap 导致了这个问题。尝试升级/降级版本。

标签: node.js reactjs npm github-pages npm-build


【解决方案1】:

您好,检查您的代码,您有一些额外的 '

/personal-site/ 处的页面错误:SyntaxError: Unexpected token '

【讨论】:

  • 感谢您的回复,但我认为这不是实际错误。无论如何,我已经检查了代码,没有这样的额外或缺少'localhost 上运行时应该会出现同样的错误。幸运的是,当我在 localhost 上运行它时,我没有收到此错误。
  • 你可以读到这个我告诉你这个,因为在此之前我有同样的错误,我已经检查过它确实在那里,所以我告诉你为什么我告诉你看到 ts 清楚地说这个 Unexpected token '
  • 如果你仍然有这个问题,你可以使用它,它将帮助你 npm "run build -prod" 然后扩展 javascript 内存节点 --max_old_space_size=4096 node_modules/@react/cli/bin /ng build --prod 希望这会起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多