Ruby:2.6.3p62(rvm)
滑轨:6.0
操作系统: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
当我浏览到“ 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
我该如何解决?它说error Command "webpack" not found.
,但Rails不应自动安装所需的所有东西吗?
答案 0 :(得分:2)
编辑:
这是我的第一篇文章之一,因此,如果我发现发布惯例有误,请原谅我。
问题来自本地计算机上的节点版本。当您创建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.
就我而言,我的计算机上安装了9.4.0版的node,而那是get-caller-file软件包不希望使用的版本。
要解决此问题,请首先确认您的节点版本,以确保它不是9.x.x:
node -v
更新节点(我使用nvm,但是other ways on GitHub网站上有node)。
nvm install node # "node" is an alias for the latest version
再次检查版本。如果它是12.10或更高,则应该一切就绪。
开始另一个全新的Rails项目,它应该可以正常工作。
祝你好运!
答案 1 :(得分:2)
我遇到了同样的问题。并尝试按照@AFOC的答案建议运行bundle exec rails webpacker:install
。然后我意识到我的节点版本与rails / webpacker不兼容。然后使用节点12.x。可以。
我也尝试删除整个应用程序,然后再次创建该应用程序,但再也没有遇到此问题,它第一次起作用。因此,在我的情况下,它是节点版本。
答案 2 :(得分:1)
我最终去除了纱线。 解决了这个问题中提出的错误后,我又遇到了毛线问题。 我不知道我是否应该交叉发布我的解决方案,因为它是相同的。或只是链接到它
https://stackoverflow.com/a/58100373/683982
希望这对某人有帮助
答案 3 :(得分:0)
我在全新的6.0安装上也遇到了这个问题,就我所知,它与节点或纱线无关。我注意到package.json中没有提到webpack,因此我运行yarn add webpack
并再次尝试。我得到以下内容,它说已编译,但页面仍未加载:
[Webpacker] Compiled all packs in /vagrant/revmtg/RevMtg/public/packs
[Webpacker] One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
所以我跑了yarn add webpack-cli
。然后我得到了Error: Cannot find module '@rails/webpacker'
。
因此,我删除了node_modules
文件夹,然后运行了bundle exec rails webpacker:install
。之后,它终于工作了。
答案 4 :(得分:0)
尝试在 Ubuntu 20.04 中建立新的 Rails 6 应用程序时,我遇到了同样的挑战。
启动Rails服务器时,出现错误:
error Command "webpack" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
09:17:58 webpacker.1 | exited with code 1
09:17:58 system | sending SIGTERM to all processes
09:17:58 watcher.1 | exited with code 1
09:17:58 web.1 | terminated by SIGTERM
这是我修复的方式:
对我来说,这个问题是由于互联网连接状况不佳而导致,无法完全安装webpacker
及其所有依赖项。因此,每次我运行命令:
bundle exec rails webpacker:install
我得到以下输出:
Installing all JavaScript dependencies [4.3.0]
run yarn add @rails/webpacker@4.3.0 from "."
yarn add v1.22.5
[1/4] Resolving packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
我只需要移到互联网连接更好的区域,然后运行命令:
bundle exec rails webpacker:install
OR
rails webpacker:install
这次,它成功运行并安装了webpacker
及其所有依赖项,并给了我最后的输出:
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ webpack-dev-server@3.11.0
info All dependencies
└─ webpack-dev-server@3.11.0
Done in 5.90s.
仅此而已。
我希望这会有所帮助
答案 5 :(得分:0)
这意味着您的应用程序中以某种方式缺少或卸载了 webpacker。
rails webpacker:install
应该可以解决您的问题。
答案 6 :(得分:0)
尝试这样做:
bundle exec rails webpacker:install
如果还是不行就试试:
npm install
yarn install check--files