(对 Rails 作出反应)引擎 "node" 与此模块不兼容。预期版本“...”

(React on Rails) The engine "node" is incompatible with this module. Expected version "..."

对于那些熟悉 react-on-rails gem 的人,或者更一般地说,yarn:

就在今天,我通过 Homebrew 将我的 Node 版本更新到了 8.8.1。现在,当我尝试 运行 bundle && yarn && foreman start -f Procfile.dev (或只是 yarn install)时,我收到以下消息:

error react-webpack-rails-tutorial@0.0.1: The engine "node" is incompatible with this module. Expected version "5.10.0".

error Found incompatible module

info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

这可能是我 运行 遇到的一个非常简单的问题,但经过几个小时的调试后我无法修复它。

我尝试在 package.json 中手动将我的 Node 版本更新为我计算机上的版本(似乎没有任何效果),通过 Homebrew 将我的版本降级到 5.10.0(但无法),甚至升级到最新版本的 gem 这意味着还要安装 webpack。

无论我做什么,我的本地服务器启动 (bundle && yarn && foreman start -f Procfile.dev) 仍然会导致上述相同的错误。对这个可怜的灵魂有什么想法吗?

我从 react-webpack-rails-tutorial github page

给你这份检查清单

Basic Demo Setup

  1. Be sure that you have Node installed! We suggest nvm, with node version v6.0 or above. See this article Updating and using nvm.

  2. git clone git@github.com:shakacode/react-webpack-rails-tutorial.git cd react-webpack-rails-tutorial

  3. Check that you have Ruby 2.3.0 or greater
  4. Check that you're using the right version of node. Run nvm list to check. Use 5.5 or greater.
  5. Check that you have Postgres installed. Run which postgres to check. Use 9.4 or greater.
  6. Check that you have qmake installed. Run which qmake to check. If missing, follow these instructions: Installing Qt and compiling capybara-webkit
  7. Check that you have Redis installed. Run which redis-server to check. If missing, install with Homebrew (brew install redis) or follow these instructions.
  8. bundle install
  9. brew install yarn
  10. yarn
  11. rake db:setup
  12. foreman start -f Procfile.hot
  13. Open a browser tab to http://localhost:3000 for the Rails app example with HOT RELOADING
  14. Try Hot Reloading steps below!
  15. foreman start -f Procfile.static
  16. Open a browser tab to http://localhost:3000 for the Rails app example.
  17. When you make changes, you have to refresh the browser page.

对于任何 运行遇到同样问题的人,我还没有找到解决潜在问题的方法,但我找到了一个临时解决方法。

简单运行

bundle && yarn --ignore-engines && foreman start -f Procfile.dev

而不是

bundle && yarn && foreman start -f Procfile.dev

我希望这可以帮助其他可能发现自己陷入同样情况的人!

您需要更新 Node.js 版本。尝试

  1. 清除 NPM 的缓存:

sudo npm cache clean -f

  1. 安装一个叫'n'
  2. 的小帮手

sudo npm install -g n

  1. 安装最新的稳定 Node.js 版本

sudo n stable