Webpacker 找不到应用程序

Rob*_*ois 25 ruby-on-rails webpack ruby-on-rails-6

我正在根据“Rails 入门”创建一个新的 Rails 应用程序。应用程序在步骤 4.1 中正常启动。但是当我创建我的第一个控制器时,我有一个 webpack 错误。

我是 webpack 的新手,我的所有文档都是红色的,但我不明白有什么问题或遗漏了什么......

  • 视窗 10 1903
  • 红宝石 2.6
  • 导轨 6.0.0
  • nodeJS 12.11.0

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 ?
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)

Sal*_*ikh 26

运行命令

rails webpacker:install
Run Code Online (Sandbox Code Playgroud)

这为我解决了这个问题。


dan*_*eto 24

这个错误似乎是关键。

Your manifest contains:
{
}
Run Code Online (Sandbox Code Playgroud)

尝试简单地yarn在您的项目目录中运行该命令。这应该会导致manifest.json创建一个文件 - 除其他外。

如果这不起作用,我在 github 上发现了这个问题,我正在逐字背诵以下可能对您有所帮助的命令。这将重置所有构建的资产和 node_modules。

rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile
Run Code Online (Sandbox Code Playgroud)

查看该链接以获取更多信息。

  • `bundle execrails webpacker:clobber` 从项目中删除 public/packs 文件夹,其中包含 `public/packs/manifest.json` 文件,`yarn` 将其恢复。对于遇到同样问题的人,最好使用“clean-webpack-plugin”。 (2认同)

ben*_*sop 11

我遇到此错误的时间比我愿意提及的时间还要长,直到我运行以下步骤:

首先,webpacker 在我的默认情况下被锁定为 4.0 版本Gemfile。我将其升级到5.0并运行bundle update

然后:

rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile
Run Code Online (Sandbox Code Playgroud)

预编译资产时出现新错误:

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.
Run Code Online (Sandbox Code Playgroud)

所以我编辑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

Run Code Online (Sandbox Code Playgroud)

只有这样才能javascript_load_tag加载。它可能并不适合所有人,但希望在相同情况下可以节省其他人的时间。


Son*_*yen 10

就像上面 Salman 的回答一样,命令

$ rails webpacker:install
Run Code Online (Sandbox Code Playgroud)

或者

$ bundle exec rails webpacker:install
Run Code Online (Sandbox Code Playgroud)

解决了这个问题。这对我来说很奇怪,因为 rails 不会自动安装 webpacker,但javascript_pack_tag无论如何都将其包含在默认布局中。但是,如果 yarn 抱怨您的节点版本,请确保安装正确的并切换到它,然后再次运行上述命令。这个简单的事情花了我一个小时才弄明白。例如:

$ nvm install 13.7
$ nvm use 13.7
$ rails webpacker:install
Run Code Online (Sandbox Code Playgroud)


CWa*_*ton 6

这是我为未来的 Rails 6.1+ 和 Ruby 2.7.1+ 用户提供的解决方案。

对我来说,发生这种情况是因为我的 webpacker gem 在Gemfile. 一旦我将其提升到 5.0 版本并运行bundle update,这个错误就消失了。看起来 webpacker 在运行时可能一直默默地失败并且从未创建该public/packs文件夹。将我的 Webpacker 更改Gemfile为最新版本为我解决了这个错误。

Gemfile 更改

DELETED gem 'webpacker',    '~> 4.0.7'
ADDED   gem 'webpacker',    '~> 5.0'
Run Code Online (Sandbox Code Playgroud)


小智 6

运行yarn add @rails/webpacker然后rails webpacker:install为我解决了这个问题。


Rob*_*ois 0

感谢您的帮助。不幸的是没有任何效果。

rails assets:clobber删除node_modules文件夹后立即返回“错误无法找到完整性文件”。(在yarn install --check-files之后起作用)。

rails assets:precompile 返回

"C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/webpack_runner.rb:23:in `exec': No such file or directory - C:\Users\[...]\site_test\node_modules\.bin/webpack (Errno::ENOENT)"
Run Code Online (Sandbox Code Playgroud)

但我发现出了问题:我电脑中的位置!可能是名字问题...