【问题标题】:Deploying Rails App via Heroku uses an old version of Node通过 Heroku 部署 Rails 应用程序使用旧版本的 Node
【发布时间】:2020-06-23 00:26:11
【问题描述】:

在我的 Ubuntu 16.04 机器上尝试通过 Heroku“git push heroku master”部署我的 Rails 应用程序时,我收到以下错误:

[2/4] Fetching packages...
remote:          error @rails/webpacker@4.2.2: The engine "node" is incompatible with this module. Expected version ">=8.16.0".
remote:        error An unexpected error occurred: "Found incompatible module".
remote:        info If you think this is a bug, please open a bug report with the information provided in "/tmp/build_c472d4366cfa53133fe29a2426a45a7b/yarn-error.log".
remote:        info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
remote:
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed

这是我的 package.json 文件(在根文件夹中):

{
  "name": "site",
  "private": true,
  "dependencies": {
    "@rails/webpacker": "4.2.2",
    "flatpickr": "^4.6.3",
    "jquery": "^3.3.1",
    "node": "^12.x",
    "node-sass": "^4.13.1",
    "reading-time": "^1.2.0",
    "simple-lightbox": "^2.1.0"
  },
  "devDependencies": {
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.10.3"
  }
}

节点--版本:

v13.10.1

heroku 运行节点 --version:

Running node --version on ⬢ -site... up, run.4229 (Hobby)
v12.16.1

【问题讨论】:

    标签: node.js ruby-on-rails heroku yarnpkg


    【解决方案1】:

    Ruby 支持 - Installed binaries

    默认情况下,具有 execjs gem 的 Rails 应用程序将在应用程序中安装默认版本的 Node。默认安装的Node版本为:

    10.15.3
    

    如果您的 Ruby 应用程序需要特定版本的节点,您应该使用多个构建包先安装节点,然后再安装 Ruby。

    $ heroku buildpacks:add heroku/nodejs
    $ heroku buildpacks:add heroku/ruby
    

    验证您的 buildpack 设置是否正确,并且 Node 位于 Ruby 之前:

    $ heroku buildpacks
    === myapp Buildpack URLs
    1. heroku/nodejs
    2. heroku/ruby
    

    完成此操作后,您需要在应用的根目录中创建一个 package.json 文件。例如,要安装 8.9.4 版,您的 package.json 可能如下所示:

    { "engines" : { "node": "8.9.4" } }
    

    您可以在 package.json 中的 engine.yarn 键中指定要使用的 Yarn 版本

    【讨论】:

      【解决方案2】:

      不确定它到底是什么,但这个问题与我使用的 Heroku buildpack (heroku-buildpack-bundler2) 有关。

      这是我为解决这个问题所做的:

      $ heroku buildpacks:set heroku/ruby
      $ heroku buildpacks:add --index 1 heroku/nodejs
      
      $ git push heroku master
      

      现在一切正常:-)

      【讨论】:

        【解决方案3】:

        https://devcenter.heroku.com/articles/deploying-nodejs

        您可以通过 package.json 在 Heroku 上指定节点版本

        {
          "name": "node-example",
          "version": "1.0.0",
          "description": "This example is so cool.",
          "main": "web.js",
          "scripts": {
            "test": "echo \"Error: no test specified\" && exit 1"
          },
          "keywords": [
            "example",
            "heroku"
          ],
          "author": "jane-doe",
          "license": "MIT",
          "dependencies": {
            "express": "^4.9.8"
          },
          "engines": {
            "node": "10.x"
          }
        }
        

        您可以在这里找到当前支持的节点版本:https://devcenter.heroku.com/articles/nodejs-support

        【讨论】:

        • 嗨,锡!谢谢您的答复。这是我的输出:[1/5] Validating package.json ... remote: error site@: The engine "node" is incompatible with this module.预期版本“13.10.1”。
        猜你喜欢
        • 2017-02-08
        • 2018-01-27
        • 2018-01-25
        • 1970-01-01
        • 2017-12-24
        • 2021-09-02
        • 1970-01-01
        • 2014-08-08
        • 2014-12-13
        相关资源
        最近更新 更多