【问题标题】:How do I make Heroku use node 14.x instead of 12.x?如何让 Heroku 使用节点 14.x 而不是 12.x?
【发布时间】:2021-06-01 07:56:39
【问题描述】:

我需要 Heroku 使用 NodeJS 14 而不是 12,我该怎么做?在我的计算机上,我使用的是节点 14,我在 package.json 的引擎中定义它(在我的仓库的根目录):

{
  "engines": {
    "node": "14.x"
  }
  ...
}

我同时安装了 heorku/nodejsheroku/rails buildpack,因为这是一个带有 webpack 的 Ruby on Rails 应用程序:

但是当我的测试是 Heroku 时,我得到了这个错误:

Error: Missing binding /app/node_modules/node-sass/vendor/linux-x64-72/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x
Found bindings for the following environments:
  - Linux 64-bit with Unsupported runtime (88)

如果我在 CI 中解决问题,我在部署时仍然会遇到问题:

-----> Installing node-v12.16.2-linux-x64
-----> Installing yarn-v1.22.4
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       yarn install v1.22.4
       [1/5] Validating package.json...
       error imok@0.1.0: The engine "node" is incompatible with this module. Expected version "14.x". Got "12.16.2"
       error Found incompatible module.
       info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

【问题讨论】:

  • 嗨,为了确定,你能显示heroku buildpacks命令的结果吗?
  • 您是否可能需要多个构建包(节点 && rails):devcenter.heroku.com/articles/…
  • @VictorBls 我没有安装 heroku cli,如果你在 buildpacks 列表之后,我有 heroku/ruby 和 heroku/nodejs。我将在问题中添加详细信息。
  • @RobertRowntree:是的,我需要并且我有多个构建包,heroku/ruby 和 heroku/nodejs。这是我问题的结尾。我会澄清的。
  • 问题在于构建包的添加顺序。 Glen 找到了解决方案。

标签: node.js heroku


【解决方案1】:

the documentation 中写道:

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

这意味着如果您部署了 Rails 应用程序,则需要删除所有构建包,然后以正确的顺序重新添加它们,首先是 heroku/node,然后是 heroku/rails

【讨论】:

  • 我不知道为什么工作构建停止工作,但这肯定解决了问题。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-14
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
  • 2015-12-02
  • 2020-10-24
  • 1970-01-01
相关资源
最近更新 更多