【问题标题】:Faild on deployment on Heroku在 Heroku 上部署失败
【发布时间】:2019-11-04 05:00:34
【问题描述】:

我用 node.js +react 制作了一个应用程序,但我无法在 heroku 上部署它。 它适用于本地主机 我试图删除 package-lock.json 文件,但没有帮助。

这是我在服务器目录中 package.json 中的脚本

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

还有我的heroku日志

*

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  8.1.1
       engines.npm (package.json):   5.0.3

       Resolving node version 8.1.1...
       Downloading and installing node 8.1.1...
       npm 5.0.3 already installed with node

-----> Restoring cache
       - node_modules

-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       added 93 packages in 7.456s

-----> Build
       Running heroku-postbuild

       > server@1.0.0 heroku-postbuild /tmp/build_52aeb2bcb298df1839239655d0215864
       > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client


       > fsevents@1.2.9 install /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/jest-haste-map/node_modules/fsevents
       > node install


       > fsevents@1.2.9 install /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/chokidar/node_modules/fsevents
       > node install


       > core-js-pure@3.1.4 postinstall /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/core-js-pure
       > node scripts/postinstall || echo "ignore"


       > core-js@2.6.9 postinstall /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/babel-runtime/node_modules/core-js
       > node scripts/postinstall || echo "ignore"

       added 1550 packages in 43.208s

       > client@0.1.0 build /tmp/build_52aeb2bcb298df1839239655d0215864/client
       > react-scripts build
        /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/@hapi/hoek/lib/deep-equal.js:17
    options = { prototype: true, ...options };
                                 ^^^ SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/@hapi/hoek/lib/index.js:9:19)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@0.1.0 build: `react-scripts build`

npm 错误!退出状态 1 npm ERR! npm 错误!在客户端失败@0.1.0 构建脚本。 npm 错误!这可能不是 npm 的问题。那里 可能是上面的附加日志输出。 npm 错误!完整的日志 此运行可在以下位置找到:npm ERR!
/tmp/npmcache.1V3q7/_logs/2019-06-21T10_03_50_779Z-debug.log npm 错误! 代码 ELIFECYCLE npm 错误! errno 1 npm 错误!服务器@1.0.0 heroku-postbuild:NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client npm ERR!退出状态 1 npm 呃! npm 错误!在 server@1.0.0 heroku-postbuild 脚本中失败。 npm 呃!这可能不是 npm 的问题。有可能 上面的附加日志输出。 npm 错误!本次运行的完整日志 可以在以下位置找到:npm ERR!
/tmp/npmcache.1V3q7/_logs/2019-06-21T10_03_50_793Z-debug.log -----> 构建失败

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/

       Love,
       Heroku
         !     Push rejected, failed to compile Node.js app.  !     Push failed*

【问题讨论】:

  • 将您的节点版本至少更新到 8.6.0 以支持对对象文字使用扩展运算符 - 请参阅支持的版本 here

标签: javascript node.js heroku deployment


【解决方案1】:

您不需要删除 package.json 文件。您只需上传除 node_modules 之外的所有文件和文件夹。 Heroku 服务器为您安装所有必需的软件包。

还有一件事,你必须在脚本标签下添加“测试”命令。

"scripts": {
    "test": "node index.js",
    "start": "node index.js"
 },

【讨论】:

  • 虽然这些可能是进一步的问题,但显示的错误是SyntaxError: Unexpected token ...,这是由于对对象文字使用了扩展运算符。使用的节点版本(8.1.1)不支持此功能
  • 尝试从脚本标签中删除所有内容,只放置测试和脚本命令。因此,您可能会知道实际问题是从哪里发生的。谢谢
猜你喜欢
  • 2021-07-19
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
  • 2021-08-25
  • 2016-02-21
相关资源
最近更新 更多