【问题标题】:React-rails install error Webpacker configuration file not foundReact-rails 安装错误 Webpacker 配置文件未找到
【发布时间】:2018-05-01 07:18:39
【问题描述】:

将 rails 3 升级到 rails 4.2.4 后,我想在我的项目中使用 react-rails gem。我遵循官方 react-rails 文档。

rake webpacker:install 收到此错误。

Webpacker configuration file not found /home/projects/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /home/projects/config/webpacker.yml
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/configuration.rb:73:in `rescue in load'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/configuration.rb:70:in `load'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/configuration.rb:66:in `data'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/configuration.rb:62:in `fetch'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/configuration.rb:17:in `compile?'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/manifest.rb:32:in `compiling?'
/home/.rvm/gems/ruby-2.3.4/gems/webpacker-3.5.2/lib/webpacker/manifest.rb:22:in `lookup'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering/webpacker_manifest_container.rb:42:in `find_asset'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering/bundle_renderer.rb:27:in `block in initialize'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering/bundle_renderer.rb:26:in `each'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering/bundle_renderer.rb:26:in `initialize'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering.rb:17:in `new'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering.rb:17:in `block in reset_pool'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/timed_queue.rb:6:in `block in initialize'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/timed_queue.rb:6:in `initialize'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/timed_queue.rb:6:in `new'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/timed_queue.rb:6:in `initialize'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/connection_pool.rb:42:in `new'
/home/.rvm/gems/ruby-2.3.4/gems/connection_pool-0.9.3/lib/connection_pool.rb:42:in `initialize'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering.rb:17:in `new'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/server_rendering.rb:17:in `reset_pool'
/home/.rvm/gems/ruby-2.3.4/gems/react-rails-2.4.4/lib/react/rails/railtie.rb:104:in `block in <class:Railtie>'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `run'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/initializable.rb:54:in `run_initializers'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/application.rb:352:in `initialize!'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/railtie.rb:194:in `public_send'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/railtie.rb:194:in `method_missing'
/home/projects/config/environment.rb:17:in `<top (required)>'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/application.rb:328:in `require_environment!'
/home/.rvm/gems/ruby-2.3.4/gems/railties-4.2.4/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/home/.rvm/gems/ruby-2.3.4/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'

请帮助我,我使用 rails 4.2.4 创建了新的演示应用程序,它运行良好,但不是我现有的应用程序。

【问题讨论】:

  • 我正在使用 rails 4.2 ...
  • "显而易见的解决方案是手动复制 config/webpacker.yml 文件"
  • 在显示上述错误后,我已经手动将 wepbacker.yml 添加到配置中。然后我将 webpacke 文件夹复制到 config 和 webpacker 中,然后将运行器复制到 bin 中,然后我运行 rake webpacker:install:react。它显示错误
  • [Webpacker] 编译失败:配置对象无效。 Webpack 已使用与 API 架构不匹配的配置对象进行初始化。

标签: ruby-on-rails ruby ruby-on-rails-4


【解决方案1】:

【讨论】:

    【解决方案2】:

    这是一个 3 步过程:

    • 第 1 步:在 config 文件夹中创建一个 webpacker.yml,以便路径为 config/webpacker.yml
    • 第 2 步:将以下内容粘贴到 webpacker.yml 文件中。
        default: &default
          source_path: app/javascript
          source_entry_path: packs
          public_root_path: public
          public_output_path: packs
          cache_path: tmp/cache/webpacker
          check_yarn_integrity: false
          webpack_compile_output: false
    
          resolved_paths: []
          cache_manifest: false
          extract_css: false
    
          static_assets_extensions:
            - .jpg
            - .jpeg
            - .png
            - .gif
            - .tiff
            - .ico
            - .svg
            - .eot
            - .otf
            - .ttf
            - .woff
            - .woff2
    
          extensions:
            - .mjs
            - .js
            - .sass
            - .scss
            - .css
            - .module.sass
            - .module.scss
            - .module.css
            - .png
            - .svg
            - .gif
            - .jpeg
            - .jpg
    
        development:
          <<: *default
          compile: true
    
          check_yarn_integrity: true
    
          dev_server:
            https: false
            host: localhost
            port: 3035
            public: localhost:3035
            hmr: false
            inline: true
            overlay: true
            compress: true
            disable_host_check: true
            use_local_ip: false
            quiet: false
            pretty: false
            headers:
              'Access-Control-Allow-Origin': '*'
            watch_options:
              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
    
          # Extract and emit a css file
          extract_css: true
    
          # Cache manifest.json for perfo`enter code here`rmance
          cache_manifest: true
    
    • 第三步:重启服务器

    【讨论】:

    • 我也有同样的问题。我没有 webpacker.yml 文件。在尝试这个时,rails 在命令行中给了我这个错误YAML syntax error occurred while parsing Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (&lt;unknown&gt;): did not find expected key while parsing a block mapping at line 1 column 2 (RuntimeError)
    【解决方案3】:

    如果你没有这些文件,可能你没有安装 Yarn https://yarnpkg.com/lang/fr/docs/install/#mac-stable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多