Rails 6.1:Webpacker 找不到 application.js

Posted

技术标签:

【中文标题】Rails 6.1:Webpacker 找不到 application.js【英文标题】:Rails 6.1: Webpacker can't find application.js 【发布时间】:2021-12-22 12:39:36 【问题描述】:

使用 rails 6.1.4 安装新应用程序。运行应用程序时,我得到以下信息......

来自浏览器:

Showing /home/james/ReachTech/app/views/layouts/application.html.erb where line #10 raised:

Webpacker can't find application.js in /home/james/ReachTech/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:


Extracted source (around line #10):
8
9
10
11
12
13
              

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

  <body>

我想使用 javascript。我已经多次重新启动应用程序。有什么建议吗?

【问题讨论】:

请分享layouts/application.html.erb的相关部分。另见文档:edgeguides.rubyonrails.org/webpacker.html 您是否尝试过运行yarn install,以便它安装所需的纱线包以使 webpack 工作? 【参考方案1】:

请运行此命令

yarn install

【讨论】:

以上是关于Rails 6.1:Webpacker 找不到 application.js的主要内容,如果未能解决你的问题,请参考以下文章

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

如何通过 Webpacker 使用 Rails 6.1 安装 Alpine JS 3

Webpacker 找不到应用程序

stylesheet_pack_tag 在带有 webpacker gem 的 rails 5.1 中找不到 app/javascript/src/application.css

Webpacker 在 /app/public/packs/manifest.json 中找不到 application.css

Webpacker 找不到 https://js.stripe.com/v3/.js