在 Rails 应用程序上创建 Ruby 时出现 Webpacker 错误
Webpacker Error While Creating Ruby On Rails App
$ rails 6.0.2 新 sample_app2
.
.
.
Using web-console 4.0.1
Using webdrivers 4.1.3
Using webpacker 4.2.2
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
run bundle binstubs bundler
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Skipped bundle since it already exists.
If you want to overwrite skipped stubs, use --force.
run bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring inserted
rails webpacker:install
Traceback (most recent call last):
4: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `'
3: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
2: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/yarn:23:in `'
1: from /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:400:in `block in replace_bin_path'
/home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:372:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
同样在执行
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
之后
我得到了相同的结果
$ yarn -v
[DEPRECATION] The trollop gem has been renamed to optimist
and will no longer be supported. Please switch to optimist
as soon as possible. Yarn v0.1.1 2011 Jesper Kjeldgaard
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ rails -v
Rails 6.0.2.1
您将 yarn 安装为 gem https://rubygems.org/gems/yarn,这是错误的。
现在你应该这样做:
卸载这个gem,gem uninstall yarn
On mac os brew install yarn
如果其他平台那么看这里:https://yarnpkg.com/lang/en/docs/install/#debian-stable
检查版本,应该是这样的:
yarn -v
1.21.1
遇到同样的错误。
首先通过命令gem uninstall yarn
卸载yarn。
会询问yn,输入yn
下一个运行:command gem update
最后检查yarn --version
$ rails 6.0.2 新 sample_app2
. . . Using web-console 4.0.1 Using webdrivers 4.1.3 Using webpacker 4.2.2 Bundle complete! 17 Gemfile dependencies, 75 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. run bundle binstubs bundler The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Skipped bundle since it already exists. If you want to overwrite skipped stubs, use --force. run bundle exec spring binstub --all * bin/rake: Spring inserted * bin/rails: Spring inserted rails webpacker:install Traceback (most recent call last): 4: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `' 3: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval' 2: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/yarn:23:in `' 1: from /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:400:in `block in replace_bin_path' /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:372:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception) Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
同样在执行
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/之后
我得到了相同的结果
$ yarn -v [DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible. Yarn v0.1.1 2011 Jesper Kjeldgaard
$ ruby -v ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ rails -v Rails 6.0.2.1
您将 yarn 安装为 gem https://rubygems.org/gems/yarn,这是错误的。 现在你应该这样做:
卸载这个gem,
gem uninstall yarn
On mac os
brew install yarn
如果其他平台那么看这里:https://yarnpkg.com/lang/en/docs/install/#debian-stable检查版本,应该是这样的:
yarn -v
1.21.1
遇到同样的错误。
首先通过命令
gem uninstall yarn
卸载yarn。会询问yn,输入yn
下一个运行:
command gem update
最后检查
yarn --version