【问题标题】:react-script build giving error while deploying to herokureact-script build 在部署到heroku时出现错误
【发布时间】:2020-09-28 09:37:24
【问题描述】:

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

//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

【问题讨论】:

    标签: node.js reactjs heroku npm


    【解决方案1】:

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

    spread operator (...) 可从Node.js v8.6 and up 获得。通过在 package.json 文件中设置 Heroku 来确保使用正确的 Node 版本:

    { 
      "engines" : { 
        "node" : ">=8.6" 
      }
    }
    

    【讨论】:

    • 感谢您的回复。它让我找到了好的解决方案。我应用了这个,但 Heroku 仍然抱怨:'engines.node 中的危险 semver range (>)',指向 devcenter.heroku.com/articles/…。该站点建议使用您在本地运行的相同版本,但建议在补丁中使用 x 以获取最新的补丁更新。最后我得到了 "node" : "12.x"
    最近更新 更多