Rails:Webpacker 4.2 在 /app/public/packs/manifest.json heroku 中找不到应用程序

新手上路,请多包涵

我有点难过。我的本地 Rails 应用程序与 webpacker 4.2 配合使用效果很好,并且做出反应,但是当部署到生产环境时,出现了美妙的 can't find application in /app/public/packs/manifest.json 错误。

这是我尝试过的:

  • 尝试为 javascript 包标签添加/删除 turbo 链接详细信息。
  • 删除了 javascript 包含标记(不确定这是否有帮助)
  • 确保我使用的是最新的 webpacker 4.2
  • 在 heroku 上手动运行 rake assets:clean && rake assets:precompile 以确保正在构建东西。

我是否缺少构建步骤或生产中会导致此问题的某些内容?还有什么要检查的?

服务器错误:

 2019-12-03T15:18:19.022024+00:00 app[web.1]: I, [2019-12-03T15:18:19.021952 #30]  INFO -- : [aa0374eb-bab1-40cc-b40b-6ae3d195e07d] Completed 500 Internal Server Error in 112ms (ActiveRecord: 30.4ms | Allocations: 21296)
2019-12-03T15:18:19.023103+00:00 app[web.1]: F, [2019-12-03T15:18:19.023029 #30] FATAL -- : [aa0374eb-bab1-40cc-b40b-6ae3d195e07d]
2019-12-03T15:18:19.023107+00:00 app[web.1]: [aa0374eb-bab1-40cc-b40b-6ae3d195e07d] ActionView::Template::Error (Webpacker can't find application in /app/public/packs/manifest.json. Possible causes:
2019-12-03T15:18:19.023109+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2019-12-03T15:18:19.023111+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2019-12-03T15:18:19.023114+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2019-12-03T15:18:19.023116+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2019-12-03T15:18:19.023118+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2019-12-03T15:18:19.023120+00:00 app[web.1]: Your manifest contains:

{
 "application.js": "/packs/js/application-2a0e2c932678ebbf2ae7.js",
"application.js.map": "/packs/js/application-2a0e2c932678ebbf2ae7.js.map",
"entrypoints": {
 "application": {
"js": [
"/packs/js/application-2a0e2c932678ebbf2ae7.js"
],
 "js.map": [
 "/packs/js/application-2a0e2c932678ebbf2ae7.js.map"
 ]
 },
 "server_rendering": {
 "js": [
 "/packs/js/server_rendering-eb794d024d4852e8ab55.js"
],
 "js.map": [
 "/packs/js/server_rendering-eb794d024d4852e8ab55.js.map"
 ]
}
 },
"server_rendering.js": "/packs/js/server_rendering-eb794d024d4852e8ab55.js",
"server_rendering.js.map": "/packs/js/server_rendering-eb794d024d4852e8ab55.js.map"
}

...

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application' %>

<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Slab:700&display=swap" rel="stylesheet">

2019-12-03T15:18:19.023193+00:00 app[web.1]: [aa0374eb-bab1-40cc-b40b-6ae3d195e07d] app/views/layouts/application.html.erb:10

Webpacker.yml

     # Note: You must restart bin/webpack-dev-server for changes to take effect

    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

      # Additional paths webpack should lookup modules
      # ['app/assets', 'engine/foo/app/assets']
      resolved_paths: ['app/assets']

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

      # Extract and emit a css file
      extract_css: false

      static_assets_extensions:
        - .jpg
        - .jpeg
        - .png
        - .gif
        - .tiff
        - .ico
        - .svg
        - .eot
        - .otf
        - .ttf
        - .woff
        - .woff2

      extensions:
        - .jsx
        - .vue
        - .mjs
        - .js
        - .sass
        - .scss
        - .css
        - .module.sass
        - .module.scss
        - .module.css
        - .png
        - .svg
        - .gif
        - .jpeg
        - .jpg

    development:
      <<: *default
      compile: true

      # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
      check_yarn_integrity: true

      # Reference: https://webpack.js.org/configuration/dev-server/
      dev_server:
        https: false
        host: localhost
        port: 3035
        public: localhost:3035
        hmr: false
        # Inline should be set to true if using HMR
        inline: true
        overlay: true
        compress: true
        disable_host_check: true
        use_local_ip: false
        quiet: 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: true

      # Extract and emit a css file
      extract_css: true

      # Cache manifest.json for performance
      cache_manifest: true

原文由 Justin 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 382
2 个回答

看起来你的 --- application.css manifest.json 这意味着你可能没有从 Webpack javascript 文件中导入任何 css。

如果这一切都是真的,那么您可以通过以下方式之一修复生产中的错误:

  • 快速(临时)修复:将 extract_css: false 添加到您的 production 块中 config/webpacker.yml (这将模仿您的本地环境)
  • 如果您不想使用 Webpacker 编译 css:从您的应用程序布局中删除 <%= stylesheet_pack_tag 'application' %>
  • 如果你想用 Webpacker 编译一些 css:从你的 Webpack javascript 导入至少一个 css 文件

原文由 rossta 发布,翻译遵循 CC BY-SA 4.0 许可协议

我在本地实例上也遇到了同样的错误。

在尝试了很多解决方法之后,以下步骤对我有用

bundle exec rails webpacker:install

虽然此命令失败并出现以下错误

gyp:未检测到 Xcode 或 CLT 版本!吉普错误!配置错误gyp ERR!堆栈错误: gyp 失败,退出代码:1 gyp ERR!堆栈在 ChildProcess.onCpExit (/Users/ _/Documents/Ruby/udemy/test/alpha-blog/alpha-blog/node_modules/node-gyp/lib/configure.js:345:16) gyp ERR!堆栈在 ChildProcess.emit (node:events:376:20) gyp ERR!堆栈在 Process.ChildProcess._handle.onexit (node:internal/child_process:284:12) gyp ERR!系统达尔文 19.6.0 gyp 错误!命令“/usr/local/Cellar/node/15.5.0/bin/node”“/Users//Documents/Ruby/udemy/test/alpha-blog/alpha-blog/node_modules/node-gyp/bin/node-_ gyp.js” “rebuild” “–verbose” “–libsass_ext=” “–libsass_cflags=” “–libsass_ldflags=” “–libsass_library=” gyp 错误! cwd /Users/***/Documents/Ruby/udemy/test/alpha-blog/alpha-blog/node_modules/node-sass gyp 错误!节点 -v v15.5.0 gyp 错误! node-gyp -v v3.8.0 gyp 错误!不好

为了纠正这个问题,我使用了以下堆栈溢出答案(在 macOS catalina 上)

https://stackoverflow.com/a/60860951/5876113

然后我运行了以下命令

bundle exec rails webpacker:install

完成上述步骤后,我没有再次收到错误。当您在 Heroku 部署中遇到问题时,请验证这是否适合您。

原文由 Kapil Gupta 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题