Webpacker::Manifest::MissingEntryError

Jon*_*y B 5 ruby-on-rails reactjs webpack

我已经开始了一个使用rails newwith的 rails 项目--webpack=react

我在database.yml 中生成了一个新控制器更新了我的PostgreSQL 密码。

到目前为止,一切正常。在这一点上,我要做的就是让 react 呈现默认的 hello_react.jsx 文件,该文件是由 rails 生成的示例文件。

当我放入<%= javascript_pack_tag 'hello_react' %>视图并运行服务器时,出现以下错误:

Webpacker::Manifest::MissingEntryError in Home#index 显示 G:/../../../myGroceryList/app/views/home/index.html.erb 其中第 1 行出现:

Webpacker can't find hello_react.js in G:/../../../myGroceryList/public/packs/manifest.json. Possible causes:

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. webpack has not yet re-run to reflect updates. You have misconfigured Webpacker's config/webpacker.yml file. Your webpack configuration is not creating a manifest. Your manifest contains: { }

I have pushed the project up to GitHub. Any thought on what is going wrong and how to fix this error?

RESOLVED: Resolution in comments

Kar*_*bur 11

强尼乙

我遇到了同样的问题。我能够确定我需要将“.jsx”添加到我的webpacker.yml.

   extensions:
     - .js
+    - .jsx
     - .sass
     - .scss
     - .css
Run Code Online (Sandbox Code Playgroud)

我还发现它webpacker:compile没有在页面刷新或文件更改时运行。我需要在每次更改后手动运行bundle exec rake assets:precompile(或bundle exec rake webpacker:compile)才能重新加载并查看更改。

我通过 Apache+Mod_Passenger 运行应用程序而不是使用rails s(我有太多的应用程序在同时开发,无法在命令行上继续启动和停止服务器)。这似乎不适用于 Webpacker 的按需编译功能。启动服务器rails s将允许我点击应用程序localhost:3000,但反应应用程序无法正确呈现。3000 上通过 Puma 服务器点击页面,我现在可以看到编译的资产在我的 Apache/Passenger 实例中工作。因此,按需编译似乎只有在通过命令行 ( rails s)启动的服务器中运行时才能正常工作......这不能正确呈现。:-/

另一种选择(比运行 2 个服务器更好)是使用bundle exec rake assets:precompilebundle exec rake webpacker:compile进行更改时在命令行上进行编译。仍然是 PITA,但至少它有效......现在。如果我找到更好的解决方案,我会更新答案。

更新

经过大量尝试,安装了不同版本的 NodeJS、Ruby、rbenv、nvm 等,我能够确定NODE_ENV没有为 Apache/Passenger 环境设置。使用 Rbenv,我能够.rbenv-vars在我的应用程序根目录中添加一个文件,其中包含:

NODE_ENV=development
RACK_ENV=development
RAILS_ENV=development
Run Code Online (Sandbox Code Playgroud)

现在,Webpacker(和 NodeJS)看到我正在开发而不是生产中运行,并且按需编译正在运行。


Jon*_*y B 5

解决方案:据我所知,当您的 public/packs 文件夹缺少 Manifest 文件或全部丢失时,就会触发此错误。在我的例子中发生的情况是 Webpackers 编译步骤默默失败并且没有创建 public/packs 文件夹。我为此检查了 webpacker gem 的修复。您可以在此处查看该修复和对话。

如果这是根本原因,那么您可以根据您喜欢的方式安装节点包 yarn install 或 使用其中任何一个进行修复npm install