'React Scripts fails to compile

I've found a bunch of somewhat related answers but can't seem to fix so far...

Bit new to React (and I'm tirrred) so have no clue - I've created a new React app with create-react-app, then added the Github Pages bits in package.json per here.

On npm run build it's failing to compile. Error below. things I've tried:

  • Removing and reinstalling node_modules
  • clearing npm cache
  • destroying and rebuilding proj from scratch

> 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


Solution 1:[1]

Given the current situation, I'd try:

  • Inspecting /Users/Mac/.npm/_logs/2017-06-14T19_52_07_541Z-debug.log
  • Re-installing create-react-app
  • Running npm start and/or npm run build without adding the GitHub pages bits

Also:

  • Shouldn't you be running npm run deploy?
  • Take a look at /Users/Mac/Sites/cintacks/src. Is there a folder called react in there?

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 kettultim