我找到了一堆有些相关的答案,但到目前为止似乎无法修复......
React 有点新(而且我很累),所以没有任何线索 - 我使用 create-react-app 创建了一个新的 React 应用程序,然后在 package.json 中添加了 here 的 Github Pages 位。
在
npm run build
上无法编译。错误如下。我尝试过的事情:
> react-scripts build
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve 'react' in '/Users/Mac/Sites/cintacks/src'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build 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! /Users/Mac/.npm/_logs/2017-06-14T19_52_07_541Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] predeploy: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] predeploy script
鉴于目前的情况,我会尝试:
/Users/Mac/.npm/_logs/2017-06-14T19_52_07_541Z-debug.log
create-react-app
npm start
和/或 npm run build
而不添加 GitHub 页面位还有:
npm run deploy
?/Users/Mac/Sites/cintacks/src
。里面有一个叫react
的文件夹吗?如果其他人遇到这个问题,我可以按照 create-react-app 中的命令提示(而不是他们的 github 文档)来解决这个问题。在 docs 中,他们说通过 npm 安装 gh-pages.. 但在命令提示符中,系统会提示您通过纱线安装:
yarn add --dev gh-pages
然后 yarn run deploy
。不完全确定为什么会有这种差异,但它适用于纱线。
如果你像我一样看到这篇文章,它也可能与 create-react-app 本身完全无关,而是与 Git 和区分大小写有关。
由于 MacOS(不区分大小写的文件系统)和 Unix OS(区分大小写)上的大小写敏感度不同,如果您将文件名更改为不同的大小写但不注意,可能会导致您的代码在 Mac 上可以工作,但在部署时失败在您的服务器上。
快速修复所有不正确的文件名:
# Untrack all of the files
$ git rm -r --cached .
# Add them back to fix the case tracking problem
$ git add .