-1

I am trying to deploy my create-react-app on heroku under my node/express server. I am using the heroku postbuild script but I am getting an error about react-script build. Well I am new to the backend side and not knowledged about heroku deployments.

//my npde server scripts
"scripts": {
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
//my client scripts
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  //The error log
  remote: /tmp/build_9c0331519287501c707a58e785c7cac2/client/node_modules/react-scripts/config/webpack.config.js:306
remote:         ...(isEnvProductionProfile && {
remote:         ^^^
remote:
remote: SyntaxError: Unexpected token ...
remote:     at createScript (vm.js:74:10)
remote:     at Object.runInThisContext (vm.js:116:10)
remote:     at Module._compile (module.js:533:28)
remote:     at Object.Module._extensions..js (module.js:580:10)
remote:     at Module.load (module.js:503:32)
remote:     at tryModuleLoad (module.js:466:12)
remote:     at Function.Module._load (module.js:458:3)
remote:     at Module.require (module.js:513:17)
remote:     at require (internal/module.js:11:18)
remote:     at Object.<anonymous> (/tmp/build_9c0331519287501c707a58e785c7cac2/client/node_modules/react-scripts/scripts/build.js:38:23)
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! [email protected] build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the [email protected] build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.eaz5f/_logs/2020-06-09T08_25_12_438Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! [email protected] heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the [email protected] heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.eaz5f/_logs/2020-06-09T08_25_12_454Z-debug.log

1 Answer 1

1

The clue is in this error line: SyntaxError: Unexpected token .... It means Node can't recognise the ... syntax.

The spread operator (...) is available from Node.js v8.6 and up. Make sure Heroku is using the right Node version by setting it in your package.json file:

{ 
  "engines" : { 
    "node" : ">=8.6" 
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. It got me in track of the good solution. I applied this but Heroku still complained: 'Dangerous semver range (>) in engines.node', pointing to devcenter.heroku.com/articles/…. This site suggests to use the same version you're locally running but it’s recommended to use an x in the patch to get the latest patch updates. At the end I ended up with "node" : "12.x"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.