Heroku Rails 7部署找不到Javascript文件(404)

4uqofj5v  于 2022-11-13  发布在  Java
关注(0)|答案(1)|浏览(129)

我有一个rails应用程序,它的javascript可以在本地正常工作,但是当我推送到Heroku时,它对我的application.js文件中的每个相对导入都得到了404:

// Simply importing activates Turbo Drive
import "@hotwired/turbo-rails";
import { Application } from "@hotwired/stimulus";

// Here we use relative imports so these aren't in import map
import HelloController from "./application/hello_controller";
import "./application/logstuff";
import "./application/main";

// Start Stimulus and register controllers
window.Stimulus = Application.start();
window.Stimulus.debug = false; // set true to enable stimulus debugging
Stimulus.register("hello", HelloController);

我在app/javascript中有我的javascript,但错误消息显示app/assets/中缺少javascript:

GET <url>/assets/application/hello_controller net::ERR_ABORTED 404

我是否遗漏了一个配置,需要切换到哪里查找javascript?
谢谢你:)

u4vypkhs

u4vypkhs1#

我也遇到过类似的问题,通过将我的app/javascript/controllers/index.js文件的内容更改为以下内容,解决了这个问题:

import { application } from "controllers/application"
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)

更多信息请点击此处-〉https://github.com/hotwired/stimulus-rails/issues/87

相关问题