在开发中一切都很好,但在Heroku中就不行了。我甚至还在HTML中添加了一些内容,如在Stimulus文档中所写:
<div data-controller="hello">
<input type="text">
<button>Greet</button>
</div>
并添加到connect()中的hello_controller.js
console.log("it works")
甚至这在heroku上也不起作用(在控制台中也是如此)。
manifest.js:
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link custom.css
index.js:
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)
application.js:
import { Application } from "@hotwired/stimulus"
const application = Application.start()
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
importmap.rb:
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "popper", to: 'popper.js', preload: true
pin "bootstrap", to: 'bootstrap.min.js', preload: true
在仅与js相关的application.html.erb中:
<%= javascript_importmap_tags %>
只有一条线索:
Uncaught TypeError: Failed to resolve module specifier "application". Relative references must start with either "/", "./", or "../".
它不应该出现在chrome中,但它出现在生产中。Heroku日志显示一切正常,部署时也一切正常,除了:
Stopping all processes with SIGTERM
Process exited with status 143
但谷歌说,这不是大问题。这里额外的宝石,我补充说:
gem "devise", "~> 4.8"
gem 'bootstrap', '~> 5.1.3'
gem "sassc-rails"
gem "rails-controller-testing"
gem "will_paginate", "~> 3.3"
group :production do
gem "pg", "1.3.5"
end
感谢你的帮助
1条答案
按热度按时间wqlqzqxt1#
我有根据的猜测是Heroku正在使用config/cable.yml中的生产适配器,该适配器要求redis。