部署部署我在浏览器控制台有以下错误之前工作后:轨道4 - JavaScript没有在Heroku
ReferenceError: require is not defined npm.self-...js:2:0
尽管这样,我的本地服务器上的JavaScript运行完美。当我在heroku上部署我的应用程序时,它不会,但是css会,所以我不确定资产管道引起的问题。我有
group :production do
gem 'pg'
gem 'rails_12factor'
end
在我的Gemfile中。我试图在本地预编译资产,甚至通过“heroku run”命令,但它没有改变任何东西。这里是我的application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require moment
//= require bootstrap-datetimepicker
$(function() {
$("#datetimepicker").datetimepicker({
locale: "en",
format: "lll"
});
});
$(function() {
$("#events").on("click", ".pager a", function() {
$.getScript(this.href);
return false;
});
});
而且npm.js:
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('../../js/transition.js')
require('../../js/alert.js')
require('../../js/button.js')
require('../../js/carousel.js')
require('../../js/collapse.js')
require('../../js/dropdown.js')
require('../../js/modal.js')
require('../../js/tooltip.js')
require('../../js/popover.js')
require('../../js/scrollspy.js')
require('../../js/tab.js')
require('../../js/affix.js')
如果你要问我可以共享GitHub的链接。谢谢!
你有预编译资产吗? –
@GaganGami是的,但预编译似乎不起作用。 –