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

Rails webpacker:install执行失败,报Dir:Class无exists?方法错误

Rails 6.1.7 + Ruby 3.2.0下Webpacker相关问题求助

我是Ruby on Rails新手,这是我的第一个项目。已成功安装Rails,能看到Rails安装成功页面:
Rails安装成功页面

我运行rails g controller home index创建第一个网页,执行成功,输出如下:

user@Ubuntu:~/dev/app$ rails g controller home index
Running via Spring preloader in process 183578
      create  app/controllers/home_controller.rb
       route  get 'home/index'
      invoke  erb
      create    app/views/home
      create    app/views/home/index.html.erb
      invoke  test_unit
      create    test/controllers/home_controller_test.rb
      invoke  helper
      create    app/helpers/home_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/home.scss

尝试访问页面时出现以下错误:

Webpacker can't find application.js in /home/user/dev/app/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:
{
}

我尝试将config/webpacker.yml中的cache_manifest: false和extract_css: false改为true,但没有效果。我怀疑Webpacker未正确安装,于是运行bundle exec rails webpacker:install,但执行失败,无法完成,输出如下:

user@Ubuntu:~/dev/app$ bundle exec rails webpacker:install
    conflict  config/webpacker.yml
Overwrite /home/user/dev/app/config/webpacker.yml? (enter "h" for help) [Ynaqdhm] n
        skip  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
rails aborted!
NoMethodError: undefined method `exists?' for Dir:Class
/home/user/dev/app/bin/rails:5:in `<top (required)>'
/home/user/dev/app/bin/spring:10:in `require'
/home/user/dev/app/bin/spring:10:in `block in <top (required)>'
/home/user/dev/app/bin/spring:7:in `<top (required)>'
Tasks: TOP => app:template

报错核心信息:

  • rails aborted!
  • NoMethodError: undefined method `exists?' for Dir:Class

环境信息:

  • Ubuntu 22.04 LTS Desktop
  • Rails版本:6.1.7
  • Ruby版本:3.2.0

请问该如何解决这个问题?这个错误过于笼统,我难以搜索到合适的解决方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 18:01:29