react-script 构建在部署到 heroku 时出错 [英] react-script build giving error while deploying to heroku

查看:61
本文介绍了react-script 构建在部署到 heroku 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 node/express 服务器下的 heroku 上部署我的 create-react-app.我正在使用 heroku postbuild 脚本,但我收到关于 react-script 构建的错误.好吧,我是后端方面的新手,不了解 heroku 部署.

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! client@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the client@0.1.0 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! noode-server@1.0.0 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 noode-server@1.0.0 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

推荐答案

线索就在这个错误行中:SyntaxError: Unexpected token ....这意味着 Node 无法识别 ... 语法.

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

传播运算符 (...) 可从 Node.js v8 获得.6 及以上.通过在 package.json 文件中进行设置,确保 Heroku 使用正确的 Node 版本:

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" 
  }
}

这篇关于react-script 构建在部署到 heroku 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆