Rails 4-Javascript没有'在Heroku部署后无法工作
Rails 4 - Javascript doesn't work after the deployment on 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"命令预编译资产,但它并没有改变任何内容。这是我的应用程序.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链接。非常感谢。
对不起,没有足够的信誉可以评论,否则会有。
浏览器中未内置require()
函数。我建议尝试删除
//= require_tree .
&手动添加javascript文件(只是为了测试,你不会得到错误),就像这个
//= require desired_js_file
//= require_tree .
预编译asset/javascript
根目录中的所有内容,并为http请求提供服务。当浏览器遇到一个包含require()
function
的js
文件时,可能会出现错误。希望这能有所帮助!
相关文章:
- JQuery-在本地工作,但未定义$,仅在部署的站点上定义
- GetcurrentPosition不'一旦部署就无法工作
- 引导程序's的javascript在本地工作,但在部署到服务器时不能工作
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- WebSocket 应用程序在部署在 Tomcat8 服务器上时无法正常工作
- WAR文件已部署,但在GlassFish上无法正常工作
- 应用程序一旦部署到Meteor.com就停止工作
- Javascript:将字符串视为数组在本地工作,但不部署在IE中
- Angular Meteor应用程序在localhost中工作,但在部署到服务器时失败
- 为什么部署(串联、缩小)AngularJS+RequireJS应用程序不工作
- 投票系统在部署到heroku时不工作
- Rails 4-Javascript没有'在Heroku部署后无法工作
- Meteor 0.9模数部署;t工作-“;找不到模块'纤维'&”;
- Jscolor在新部署的第一次回发后停止工作,但在重新加载的回发后继续工作
- 当使用MUP(流星)部署时,Meteor.js i18n包无法工作
- MUP将失败部署到在另一台服务器上工作的项目上
- 工具提示在本地主机上工作,但不在已部署的站点上
- Sails.js websockets在localhost中工作,但在我部署到Openshift后就不工作了
- ruby on rails-Javascript在本地工作,但在部署到Heroku时不再工作.(带涡轮连杆.)
- 什么's是部署coffescription的首选工作流程