Webpacker 在 /app/public/packs/manifest.json 中找不到 application.js 并且删除 node_modules 文件夹后无法预编译资产

问题描述 投票:0回答:4

我正在使用 Ruby 2.7.1、Rails 5.2、Webpacker 5.4.3。我刚刚安装了 Stimulus 和 Webpacker 以添加一些功能。

我只使用 scss,而不是通过 webpacker。我添加 webpacker 的目的只是一个刺激控制器和动作。

我还将 Nodejs 构建包添加到 Heroku,并将其放置在我的 Ruby 构建包之上。

在本地一切正常,但是当我部署到 Heroku 时,出现以下错误。

我已经尝试了大多数SO线程,包括Rails:Webpacker 4.2无法在/app/public/packs/manifest.json heroku中找到应用程序中的所有步骤

然后我在加载页面时遇到另一个错误:

ActionView::Template::Error (Webpacker can't find application.js in /app/public/packs/manifest.json. Possible causes:
2022-02-17T00:23:41.046861+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2022-02-17T00:23:41.046862+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2022-02-17T00:23:41.046862+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2022-02-17T00:23:41.046863+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2022-02-17T00:23:41.046863+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2022-02-17T00:23:41.046864+00:00 app[web.1]: Your manifest contains:
2022-02-17T00:23:41.046864+00:00 app[web.1]: {
2022-02-17T00:23:41.046864+00:00 app[web.1]: }
2022-02-17T00:23:41.046865+00:00 app[web.1]: ):
2022-02-17T00:23:41.049630+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      7:
2022-02-17T00:23:41.049632+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049633+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]      9:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049645+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     10:     <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
2022-02-17T00:23:41.049652+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     11:     <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
2022-02-17T00:23:41.049652+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     12:
2022-02-17T00:23:41.049653+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]     13:     <%= action_cable_meta_tag %>
2022-02-17T00:23:41.049678+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a]
2022-02-17T00:23:41.049817+00:00 app[web.1]: [b001178d-5a2c-4b96-b887-d38510bf610a] app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb___2567613171312260909_150400'

我的 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
  webpack_compile_output: true

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

  # 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:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: 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
    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: true

  # Extract and emit a css file
  extract_css: false

  # Cache manifest.json for performance
  cache_manifest: true

Application.html.erb:

  <head>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <%= csrf_meta_tags %>
    
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">

    <%= action_cable_meta_tag %>
    <%= render 'content/cookie_consent' %>
  </head>
来自heroku 服务器的

manifest.json:

{
  "application.js": "/packs/js/application-7cfb688d908cd6b44d3a.js",
  "application.js.map": "/packs/js/application-7cfb688d908cd6b44d3a.js.map",
  "entrypoints": {
    "application": {
      "js": [
        "/packs/js/application-7cfb688d908cd6b44d3a.js"
      ],
      "js.map": [
        "/packs/js/application-7cfb688d908cd6b44d3a.js.map"
      ]
    }
  }
}

应用程序/javascript/packs/application.js:

import "controllers"
import '../stylesheets/application'; // have tried it both with and without this included
node.js ruby-on-rails heroku webpack webpacker
4个回答
0
投票

您能提供完整的 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: true

也许这会有帮助?

https://github.com/rails/webpacker/issues/2674


0
投票

我不确定这个问题最终是如何解决的。

我将 Ruby 从 2.7.1 更新到了 2.7.5 捆绑安装

我收到一条安装 Graphviz 的消息,我在 gemfile 中添加了:

gem 'ruby-graphviz', '~> 1.2', '>= 1.2.3'

捆绑安装

本地运行:

rake assets:precompile

添加到 gemfile.lock

PLATFORMS
  x86_64-darwin-21 //this existed
  x86_64-linux //this was added

推送到 Heroku 并且成功了。


0
投票

通过

npm
使用
npm install
安装软件包时遇到此问题。通过
yarn
切换到
yarn install
,这一切都对我有用。

使用 Rails 版本

6.1.6
顺便说一句。


0
投票

我在 Rails 6 中遇到过这个问题,发现这个解决方案有效:

npm install --save-dev @babel/plugin-proposal-private-methods
npm install --save-dev @babel/plugin-proposal-private-property-in-object
rm package-lock.json # `rm` aliases to move it to the trash
yarn

这是 Rails 6.1.7.6、node v16.13.1、ruby 2.7.1p83

我在 High Sierra 的旧 MacBook 上运行,无法运行任何示例 Rails 7 应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.