You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails应用Webpacker配置异常:manifest.json为空且找不到application.js

Rails Webpacker配置故障:manifest.json为空,无法找到application.js

创建Rails应用时遭遇Webpacker配置问题,Webpack生成的manifest.json为空,Webpacker无法在路径/home/tony/code/Tonyaguilar10/Proton/public/packs/manifest.json中找到application.js。已花费两天时间尝试重装Webpacker、替换相关组件,参考过ChatGPT和StackOverflow方案,均未解决。

具体报错信息:

Webpacker can't find application.js in /home/tony/code/Tonyaguilar10/Proton/public/packs/manifest.json.

可能原因排查方向:

  • 未使用webpack -w或webpack-dev-server时,需在对应环境的webpacker.yml中设置compile: true
  • webpack未重新运行以同步更新
  • Webpacker的config/webpacker.yml文件配置错误
  • webpack配置未生成manifest

当前manifest.json内容:

{
  "entrypoints": {}
}

页面中触发问题的代码:

<%= javascript_pack_tag "application" %>

Gemfile内容:

ruby '3.0.3'
gem 'uglifier', '>= 4.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.7', '>= 6.1.7.3'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem "bootstrap", "~> 5.2"
gem "simple_form"
#gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 6.0.0.beta.7'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  gem 'spring'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver', '>= 4.0.0.rc1'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

webpacker.yml内容:

default: &default
  source_path: app/javascript
  source_entry_path: /
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/webpacker
  webpack_compile_output: true

  # Additional paths webpack should look up modules
  # ['app/assets', 'engine/foo/app/assets']
  additional_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

development:
  <<: *default
  compile: true

  dev_server:
    https: false
    host: localhost
    port: 3035
    # Hot Module Replacement updates modules while the application is running without a full reload
    hmr: false
    # Defaults to the inverse of hmr. Uncomment to manually set this.
    # live_reload: true
    client:
      # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
      overlay: true
      # May also be a string
      # webSocketURL:
      #  hostname: "0.0.0.0"
      #  pathname: "/ws"
      #  port: 8080
    # Should we use gzip compression?
    compress: true
    # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
    allowed_hosts: "all"
    pretty: true
    headers:
      'Access-Control-Allow-Origin': '*'
    static:
      watch:
        ignored: '**/node_modules/**'

test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Cache manifest.json for performance
  cache_manifest: true

package.json内容:

{
  "name": "app",
  "private": true,
  "dependencies": {
    "@rails/webpacker": "^6.0.0-rc.6",
    "webpack": "^5.53.0",
    "webpack-cli": "^4.8.0"
  },
  "version": "0.1.0",
  "babel": {
    "presets": [
      "./node_modules/@rails/webpacker/package/babel/preset.js"
    ]
  },
  "browserslist": [
    "defaults"
  ],
  "devDependencies": {
    "@webpack-cli/serve": "^2.0.5",
    "webpack-dev-server": "^4.15.1"
  }
}

已尝试的操作:

rails webpacker:install
bundle exec rails webpacker:install
rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile

执行操作时的警告信息:

警告 " > @webpack-cli/serve@2.0.5" 存在不兼容的对等依赖 "webpack-cli@5.x.x"。


内容的提问来源于stack exchange,提问作者Tony Miranda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 22:14:55