React Scripts无法编译

时间:2017-06-14 20:05:10

标签: node.js reactjs npm github-pages

我发现了一些有些相关的答案,但到目前为止似乎无法解决......

React的新功能(我已经过了)所以不知道 - 我用create-react-app创建了一个新的React应用程序,然后在package.json中添加了Github Pages位{ {3}}

npm run build它未能编译。错误如下。我尝试过的事情:

  • 删除并重新安装node_modules
  • 清除npm缓存
  • 从头开始摧毁和重建项目
> 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! cintacks@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cintacks@0.1.0 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! cintacks@0.1.0 predeploy: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cintacks@0.1.0 predeploy script

2 个答案:

答案 0 :(得分:0)

鉴于目前的情况,我会尝试:

  • 检查/Users/Mac/.npm/_logs/2017-06-14T19_52_07_541Z-debug.log
  • 重新安装create-react-app
  • 在不添加GitHub页面位的情况下运行npm start和/或npm run build

此外:

  • 你不应该在运行npm run deploy吗?
  • 看看/Users/Mac/Sites/cintacks/src。那里有一个名为react的文件夹吗?

答案 1 :(得分:0)

If anyone else runs into this issue, I managed to fix this by following the command prompts within create-react-app, rather than their github documentation. In the docs, they say to install gh-pages via npm.. but in the command prompt, you're prompted to install via yarn: yarn add --dev gh-pages then yarn run deploy. Not entirely sure why the difference but it worked with yarn.