我正在根据“ Rails入门”创建一个新的Rails应用程序。该应用程序通常在步骤4.1中启动。但是,当我创建第一个控制器时,我遇到了一个webpack错误。
我是Webpack的新手,我将所有文档都涂成红色,但是我不明白是哪里错了...
rails webpacker:install
identical config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
The JavaScript app source directory already exists
apply C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
Copying binstubs
exist bin
identical bin/webpack
identical bin/webpack-dev-server
append .gitignore
Installing all JavaScript dependencies [4.0.7]
run yarn add @rails/webpacker from "."
yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > webpack-dev-server@3.8.2" has unmet peer dependency "webpack@^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ @rails/webpacker@4.0.7
info All dependencies
└─ @rails/webpacker@4.0.7
Done in 4.48s.
Installing dev server for live reloading
run yarn add --dev webpack-dev-server from "."
yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
warning " > webpack-dev-server@3.8.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ webpack-dev-server@3.8.2
info All dependencies
└─ webpack-dev-server@3.8.2
Done in 4.92s.
Webpacker successfully installed �???
Webpacker::Manifest::MissingEntryError in Welcome#index
Showing C:/Users/[...]/site_test/app/views/layouts/application.html.erb where line #9 raised:
Webpacker can't find application in C:/Users/[...]/site_test/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:
{
}
Extracted source (around line #9):
7
8 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9 <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10 </head>
11 <body>
12
答案 0 :(得分:3)
就像上面Salman的回答一样,命令
$ rails webpacker:install
或
$ bundle exec rails webpacker:install
解决了问题。这对我来说很奇怪,因为Rails不会自动安装webpacker,但无论如何都将javascript_pack_tag
包含在默认布局中。但是,如果yarn抱怨您的节点版本,请确保安装正确的版本并切换到该版本,然后再次运行以上命令。这个简单的事情花了我一个小时才弄清楚。例如:
$ nvm install 13.7
$ nvm use 13.7
$ rails webpacker:install
答案 1 :(得分:3)
我遇到这个错误的时间比我想提到的要长,直到我运行以下步骤:
首先,默认情况下,我的 Gemfile
中的 webpacker 被锁定在 4.0 版中。我将其升级到 5.0 并运行 bundle update
。
那么:
rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile
预编译资产时出现新错误:
yarn install v1.22.4
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.36s.
I, [2021-04-09T11:04:33.781374 #16062] INFO -- : Writing /app/public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js
I, [2021-04-09T11:04:33.781915 #16062] INFO -- : Writing /app/public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js.gz
Compiling...
Compilation failed:
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
所以我编辑了 config/webpack/environment.js
文件来阅读:
const { environment } = require('@rails/webpacker')
const customConfig = {
resolve: {
fallback: {
dgram: false,
fs: false,
net: false,
tls: false,
child_process: false
}
}
};
environment.config.delete('node.dgram')
environment.config.delete('node.fs')
environment.config.delete('node.net')
environment.config.delete('node.tls')
environment.config.delete('node.child_process')
environment.config.merge(customConfig);
module.exports = environment
只有这样才能加载 javascript_load_tag
。它可能并不适合所有人,但希望在相同情况下可以为其他人节省时间。
答案 2 :(得分:2)
我也遇到了同样的错误-已为我修复:我的NODE_ENV
文件中设置了一个.zshrc
环境变量,这导致Webpack构建使用错误的环境配置,未修复该环境变量给我(unset NODE_ENV
)
答案 3 :(得分:1)
这是我为未来的 Rails 6.1+ 和 Ruby 2.7.1+ 用户提供的解决方案。
对我来说这是因为我的 webpacker gem 在
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@WebServlet("/Auth")
public class Auth extends HttpServlet {
private static final long serialVersionUID = 1L;
public Auth() {
Statement stmt = null;
try {
Connection con = DatabaseConnection.initializeDatabase();
System.out.println("Connected database successfully...");
......
中设置为 4.0 版本。一旦我将它提升到 5.0 版本并运行 Gemfile
,这个错误就消失了。看起来 webpacker 在运行时可能一直默默地失败并且从未创建 bundle update
文件夹。将我的 public/packs
更改为最新版本的 Webpacker 为我解决了这个错误。
Gemfile 更改
Gemfile
我希望这会有所帮助。快乐编码!
答案 4 :(得分:0)
此错误似乎是关键。
variables()
尝试仅在项目目录中运行Your manifest contains:
{
}
命令。这将导致创建yarn
文件-除其他外。
如果这不起作用,我在github上找到了this issue,我在其中 verbatim 引用以下可能对您有帮助的命令。这将重置所有构建的资产和node_modules。
manifest.json
查看该链接以获取更多信息。
答案 5 :(得分:0)
感谢您的帮助。不幸的是,没有任何效果。
rails asset:clobber在删除node_modules文件夹后立即返回“错误找不到完整性文件”。 (安装纱后--check-files后可以使用。)
and rails asset:precompile return“ C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/webpack_runner.rb:23:`exec中:没有这样的文件或目录-C:\ Users [...] \ site_test \ node_modules.bin / webpack(Errno :: ENOENT)“
但是我发现了问题所在:计算机中的位置! 可能是名称问题...
答案 6 :(得分:0)
我在Rails 5.2应用程序上收到此错误消息,在其中我按照其自述文件中的说明添加了Webpacker。
尝试了其他事情之后,我尝试启动webpacker-dev-server(即使不是必需的),只是看它是否会显示出更有用的错误。它做到了:
$ ./bin/webpack-dev-server
warning package.json: No license field
Another program is running on port 3035. Set a new port in for dev_server
然后我切换到另一个正在运行的项目,该项目也使用Webpacker,并关闭了它的webpack-dev-server(仅按ctrl + c:ed正在运行的服务器)。现在,当我在这个新项目中重新加载页面时,我不再收到错误。即使没有我手动运行webpack-dev-server。
您可以在config/webpacker.yml
部分的dev_server:
中更改此端口。必要时请不要忘记在config/initializers/content_security_policy.rb
中进行更新。
答案 7 :(得分:0)
运行命令
rails webpacker:install
这为我解决了问题。
答案 8 :(得分:0)
为我解决这个问题的是将 nodejs 降级到其稳定版本(我不小心下载了最新版本),然后再次创建新的 rails 应用程序。
答案 9 :(得分:-2)
从某处降落。空清单。错误:Welcome#index中的Webpacker :: Manifest :: MissingEntryError我将其塞在public / packs / manifest.json中现在她说法语。
{
"application.js": "/packs/js/application-9afcbb5693aa87623e69.js",
"application.js.map": "/packs/js/application-9afcbb5693aa87623e69.js.map",
"entrypoints": {
"application": {
"js": [
"/packs/js/application-9afcbb5693aa87623e69.js"
],
"js.map": [
"/packs/js/application-9afcbb5693aa87623e69.js.map"
]
}
}
}