运行 Rails 服务器 - Webpacker 安装

Running Rails Server - Webpacker installation

我已按照 Rails 上的设置 Ruby 详细说明:https://gorails.com/setup/osx/10.14-mojave,但我在获取 Rails 服务器 运行...

ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Michaels-MBP:myapp mh$ rbenv versions
  system
* 2.7.1 (set by /Users/mh/myapp/.ruby-version)
Michaels-MBP:myapp mh$ rails -v
Rails 6.0.3.2

当 运行:

rails server

我最终得到:

/Users/mh/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/mh/myapp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/mh/myapp/config/webpacker.yml (RuntimeError)

运行 rails webpacker 安装给我:

sh: node: command not found
sh: nodejs: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/

我已经使用网站 installer.pkg 安装了 Node.js,并得到以下信息:

Michaels-MBP:myapp mh$ brew install yarn
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-14.4.0.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/06/06ef204701e93bbcf3909dba4ac9d3ca1d4df
######################################################################## 100.0%
==> Downloading https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/499
######################################################################## 100.0%
==> Installing dependencies for yarn: node
==> Installing yarn dependency: node
==> Pouring node-14.4.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
  rm '/usr/local/bin/node'

Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
  /usr/local/Cellar/node/14.4.0: 4,659 files, 60.8MB
==> Installing yarn
  /usr/local/Cellar/yarn/1.22.4: 14 files, 5MB, built in 2 seconds
==> Caveats
==> node
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
Michaels-MBP:myapp mh$ brew link --overwrite node
Linking /usr/local/Cellar/node/14.4.0... 
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.
Michaels-MBP:myapp mh$ brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`

它在 Yarn 安装中提到垫片是 'before'PATH 中的 rbenv 垫片?我不确定那是什么意思...

这是我的 PATH 的副本 - 我知道它可能搞砸了...


export PATH="/usr/local/opt/ruby/bin:$PATH"

alias laptop='bash <(curl -s https://raw.githubusercontent.com/monfresh/laptop/master/laptop)'



eval "$(hub alias -s)"

if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

export PATH="$HOME/.bin:$PATH"

我是这样解决这个问题的:

  • 使用自制软件
    $ brew install node
  • 然后安装webpacker
    $ rails webpacker:install
  • 确保所有包都是最新的
    $ yarn install --check-files
  • 还有...祝你好运,启动你的 Rails 服务器
    $ rails s