node.js - 部署到 Heroku 失败。移动文件与 Node 版本不兼容

标签 node.js heroku yarnpkg ruby-on-rails-6 precompile

我正在努力将新的 Rails 6 应用程序部署到 heroku。它在我的本地运行良好。在部署过程中,我收到以下输出。

不幸的是,我是 webpack 和 yarn 的新手。这似乎是 move-file 的版本/依赖性问题,而 move-file 又似乎是 webpacker 的依赖性。但是,我不知道如何解决这个问题。

似乎归结为这一行:

error move-file@2.0.0: The engine "node" is incompatible with this module. Expected version ">=10.17". Got "10.15.3"

但是, Node 不是我的 Node 模块之一,而是似乎是已安装的二进制文件。当我运行时

node - v

我得到:v12.16.1

如有任何帮助,我们将不胜感激。

remote:        Removing bundler (2.0.2)
remote:        Bundle completed (201.39s)
remote:        Cleaning up the bundler cache.
remote: -----> Installing node-v10.15.3-linux-x64
remote: -----> Installing yarn-v1.16.0
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v1.16.0
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info fsevents@1.2.13: The platform "linux" is incompatible with this module.
remote:        info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        error move-file@2.0.0: The engine "node" is incompatible with this module. Expected version ">=10.17". Got "10.15.3"
remote:        error Found incompatible module.
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

如果您需要任何进一步的日志或代码示例,请告诉我。我很茫然。

===================== 更新:

我在 heroku 上找到了关于 buildpacks 和 node 的文档: - https://devcenter.heroku.com/articles/nodejs-support

基于此,我将 package.json 文件更改为如下所示:

  },
  "version": "0.1.0",
  "engines": {
    "node": "12.16.x"
  },
  "devDependencies": {
    "webpack-dev-server": "^3.10.3"
  }

现在,错误消息已更改为:

remote:        Running: rake assets:precompile
remote:        yarn install v1.16.0
remote:        [1/5] Validating package.json...
remote:        error jobpro@0.1.0: The engine "node" is incompatible with this module. Expected version "12.16.x". Got "10.15.3"
remote:        error Found incompatible module.
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 文件中的更新会导致 heroku 使用指定的 Node 版本。然而,事实并非如此。

The question is: How can I define which node version heroku uses?

最佳答案

解决这个问题需要一些研究。 Heroku 可以为每个应用程序应用多个构建包。在这种情况下,顺序很重要。我指定先运行 nodejs buidlpack,然后再运行 ruby​​ buildpack。 只有这样,package.json 中的“引擎”定义才会生效。如果您使用 ruby​​ buildpack, Node 版本默认为 10.15.3。但是,如果您先执行 nodejs buildpack,它将安装 package.json 文件中指定的版本。 https://devcenter.heroku.com/articles/ruby-support#installed-binaries

关于node.js - 部署到 Heroku 失败。移动文件与 Node 版本不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61758641/

相关文章:

javascript - 我可以在 NodeJS、CSharp 和 WebCrypto 之间使用 DH/ECDH 方法吗?

javascript - Q.js promise 与 Node 。 `socket` 上缺少错误处理程序。类型错误 : Cannot call method 'then' of undefined

javascript - 使用 webpack ou npm 在多个包中拆分 javascript Javascript 项目

node.js - 错误 : Cannot find module 'node-linux-x64/package.json' - pushing to Heroku for first time

javascript - 部署到 heroku(gulp 未找到错误)

java - 如何通过部署 java heroku 修复语言级别

node.js - 在 win10 中,我执行 yarn add protobufjs,但错误显示 : error An unexpected error occurred: "EPERM: operation not permitted, unlink

node.js - Grunt Imagemin 没有优化图像

node.js - yarn 尝试安装 node-sass 的问题

NPM 坚持使用 CodeArtifact,甚至在公共(public)注册表上也是如此