Webpacker 在 /app/public/packs/manifest.json 中找不到 application.js 删除 node_modules 文件夹后无法预编译资产
Webpacker can't find application.js in /app/public/packs/manifest.json and I can't precompile assets after deleting node_modules folder
我正在使用 Ruby 2.7.1,Rails 5.2,Webpacker 5.4.3。我刚刚安装了 Stimulus 和 Webpacker 以添加一些功能。
我只使用 scss 而不是通过 webpacker。我为 webpacker 添加的只是一个单一的刺激控制器和动作。
我也将 nodejs buildpack 添加到 Heroku,它位于我的 Ruby buildpack 之上。
在本地一切正常,但是当我部署到 Heroku 时出现以下错误。
我已经尝试了大部分 SO 线程,包括
中的所有步骤
然后我在加载页面时遇到了另一个错误:
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>
manifest.json 来自 heroku 服务器:
{
"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"
]
}
}
}
app/javascript/packs/application.js:
import "controllers"
import '../stylesheets/application'; // have tried it both with and without this included
你能提供完整的 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
也许这会有所帮助?
我不确定这最终是如何解决的。
我将 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 并且成功了。
我正在使用 Ruby 2.7.1,Rails 5.2,Webpacker 5.4.3。我刚刚安装了 Stimulus 和 Webpacker 以添加一些功能。
我只使用 scss 而不是通过 webpacker。我为 webpacker 添加的只是一个单一的刺激控制器和动作。
我也将 nodejs buildpack 添加到 Heroku,它位于我的 Ruby buildpack 之上。
在本地一切正常,但是当我部署到 Heroku 时出现以下错误。
我已经尝试了大部分 SO 线程,包括
然后我在加载页面时遇到了另一个错误:
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>
manifest.json 来自 heroku 服务器:
{
"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"
]
}
}
}
app/javascript/packs/application.js:
import "controllers"
import '../stylesheets/application'; // have tried it both with and without this included
你能提供完整的 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
也许这会有所帮助?
我不确定这最终是如何解决的。
我将 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 并且成功了。