簡體   English   中英

通過 Heroku 部署 Rails App 使用舊版本的 Node

[英]Deploying Rails App via Heroku uses an old version of Node

在我的 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

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

不確定它到底是什么,但這個問題與我使用的 Heroku buildpack (heroku-buildpack-bundler2) 有關

這是我為解決它所做的:

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

$ git push heroku master

現在一切正常:-)

Ruby 支持 - 已安裝的二進制文件

默認情況下,具有 execjs gem 的 Rails 應用程序將在應用程序中安裝默認版本的 Node。 默認安裝的Node版本為:

10.15.3

如果您的 Ruby 應用程序需要特定版本的 node,您應該使用多個 buildpacks 來先安裝 node,然后再安裝 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 中的engines.yarn 鍵中指定要使用的Yarn 版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM