win*_*yer 6 ruby-on-rails webpack ruby-on-rails-6
Ruby:2.6.3p62(rvm)
Rails:6.0
OS:macOS 10.14.6
全新的Rails 6.0应用程序:
$ rails new testshop2
$ cd testshop2
$ rails g controller Page index
$ rails s
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Run Code Online (Sandbox Code Playgroud)
当我浏览到` http:// localhost:3000 / page / index '时,系统会遇到以下错误:
Started GET "/page/index" for ::1 at 2019-09-23 17:06:12 +0200
(0.4ms) SELECT sqlite_version(*)
Processing by PageController#index as HTML
Rendering page/index.html.erb within layouts/application
Rendered page/index.html.erb within layouts/application (Duration: 1.8ms | Allocations: 206)
[Webpacker] Compiling…
[Webpacker] Compilation failed:
error Command "webpack" not found.
Completed 500 Internal Server Error in 2021ms (ActiveRecord: 0.0ms | Allocations: 640080)
ActionView::Template::Error (Webpacker can't find application in /Users/stefan/Github/sandbox/testshop2/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
6: <%= csp_meta_tag %>
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10: </head>
11:
12: <body>
app/views/layouts/application.html.erb:9
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?它说,error Command "webpack" not found.但Rails不应该自动安装所有需要的东西吗?
当我尝试在Ubuntu 20.04中设置新的Rails 6应用程序时,我也遇到了同样的挑战。
\n当我启动 Rails 服务器时,出现错误:
\nerror Command "webpack" not found.\ninfo Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.\n09:17:58 webpacker.1 | exited with code 1\n09:17:58 system | sending SIGTERM to all processes\n09:17:58 watcher.1 | exited with code 1\n09:17:58 web.1 | terminated by SIGTERM\nRun Code Online (Sandbox Code Playgroud)\n这是我修复它的方法:
\n对我来说,问题是由于互联网连接较差,无法完全安装webpacker及其所有依赖项。所以每次我运行命令时:
bundle exec rails webpacker:install\nRun Code Online (Sandbox Code Playgroud)\n我得到这个输出:
\nInstalling all JavaScript dependencies [4.3.0]\n run yarn add @rails/webpacker@4.3.0 from "."\nyarn add v1.22.5\n[1/4] Resolving packages...\ninfo There appears to be trouble with your network connection. Retrying...\ninfo There appears to be trouble with your network connection. Retrying...\nRun Code Online (Sandbox Code Playgroud)\n我只需移动到互联网连接更好的区域,然后运行命令:
\nbundle exec rails webpacker:install\nRun Code Online (Sandbox Code Playgroud)\n或者
\nrails webpacker:install\nRun Code Online (Sandbox Code Playgroud)\n这次,它成功运行并安装了webpacker它的所有依赖项,它给了我最终的输出:
[4/4] Building fresh packages...\nsuccess Saved 1 new dependency.\ninfo Direct dependencies\n\xe2\x94\x94\xe2\x94\x80 webpack-dev-server@3.11.0\ninfo All dependencies\n\xe2\x94\x94\xe2\x94\x80 webpack-dev-server@3.11.0\nDone in 5.90s.\nRun Code Online (Sandbox Code Playgroud)\n
编辑:
这是我的第一篇文章,所以如果我弄错了发布约定,请原谅我。
问题来自本地计算机上的节点版本。当您创建 Rails 应用程序时,您可能会弹出这样的错误:
The JavaScript app source directory already exists
apply /Users/mconiaris/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
Copying binstubs
exist bin
create bin/webpack
create bin/webpack-dev-server
append .gitignore
Installing all JavaScript dependencies [4.0.7]
run yarn add @rails/webpacker from "."
yarn add v1.17.3
info No lockfile found.
[1/4] Resolving packages...
warning @rails/webpacker > postcss-preset-env > postcss-color-functional-notation > postcss-values-parser > flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
[2/4] Fetching packages...
error get-caller-file@2.0.5: The engine "node" is incompatible with this module. Expected version "6.* || 8.* || >= 10.*". Got "9.4.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Run Code Online (Sandbox Code Playgroud)
就我而言,我的计算机上安装了 9.4.0 版的 node,这是 get-caller-file 包不想使用的一个版本。
要解决此问题,请先确认您的节点版本以确保它不是 9.xx:
node -v
Run Code Online (Sandbox Code Playgroud)
更新节点(我使用 nvm,但在节点网站的GitHub上还有其他方法)。
nvm install node # "node" is an alias for the latest version
Run Code Online (Sandbox Code Playgroud)
再次检查版本。如果它是 12.10 或更高版本,您应该已准备就绪。
开始另一个全新的 rails 项目,它应该可以正常工作。
祝你好运!
小智 5
我遇到了同样的问题。并尝试bundle exec rails webpacker:install按照@AFOC 的回答建议运行。然后我意识到我的节点版本与 rails/webpacker 不兼容。然后使用节点 12.x。有用。
我也通过删除整个应用程序重试,再次创建应用程序,没有再次遇到这个问题,它第一次工作。所以就我而言,它是节点版本。