我使用Ruby 2.7.1,Rails 5.2,Webpacker 5.4.3。我刚刚安装了Stimulus和Webpacker来添加一些功能。
我只使用scss,而不是通过webpacker。所有我已经添加了webpacker是一个单一的刺激控制器和行动。
我还将nodejs buildpack添加到Heroku中,它位于Ruby buildpack之上。
这一切都在本地工作正常,但当我部署到Heroku时,我得到了下面的错误。
我已经尝试了大多数SO线程,包括Rails: Webpacker 4.2 can't find application in /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>
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
4条答案
按热度按时间bqf10yzr1#
你能提供完整的webpacker.yml吗?
也许你在默认情况下错过了什么?
也许这个能帮上忙
https://github.com/rails/webpacker/issues/2674
j2cgzkjk2#
我不知道这件事是怎么解决的。
我将Ruby从2.7.1 bundle install更新到了2.7.5
我有一个消息来安装Graphviz,我添加到gemfile:
bundle install
本地运行:
添加到gemfile.lock
推到Heroku和它的工作。
f87krz0w3#
使用
npm
通过npm install
安装软件包时遇到此问题。切换到yarn
通过yarn install
和它的所有工作为我。使用rails版本
6.1.6
btw。1hdlvixo4#
我在Rails 6中遇到了这个问题,发现这个解决方案很有效:
这是Rails 6.1.7.6,node v16.13.1,ruby 2.7.1p83
我用的是high sierra上的旧macbook,无法运行任何rails 7示例应用程序。