我正在为我的公司项目使用jquery,backbonejs,underscorejs和bootstrap.有时我在chrome中遇到这个错误.
未捕获的TypeError:无法读取未定义的属性"fn"
在我的main.js中,我的垫片是这样的
require.config({ paths: { jquery: 'libs/jquery/jquery', underscore: 'libs/underscore/underscore', backbone: 'libs/backbone/backbone', backboneeventbinder: 'libs/backbone.eventbinder.min', bootstrap: 'libs/bootstrap', jquerytablesorter: 'libs/tablesorter/jquery.tablesorter', tablesorter: 'libs/tablesorter/tables', ajaxupload: 'libs/ajax-upload', templates: '../templates' }, shim: { 'backbone': { deps: ['underscore', 'jquery'], exports: 'Backbone' }, 'underscore': { exports: '_' }, } }); require(['app', ], function(App) { App.initialize(); });
我已经为jquery,underscorejs和backbonejs插入了.noConflict().
我的app.js.
// Filename: app.js define(['jquery', 'underscore', 'backbone', 'backboneeventbinder', 'bootstrap', 'ajaxupload', 'router', // Request router.js ], function($, _, Backbone, Bootstrap, Backboneeventbinder, Ajaxupload, Router) { $.noConflict(); _.noConflict(); Backbone.noConflict(); var initialize = function() { Router.initialize(); }; return { initialize: initialize }; });
这是我的chrome的截图
它类似于bootstrap.
非常感谢提前.
我的方式是导入jquery库。
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
我需要在bootstrap之前先加载jquery.
require.config({ paths: { jquery: 'libs/jquery/jquery', underscore: 'libs/underscore/underscore', backbone: 'libs/backbone/backbone', bootstrap: 'libs/bootstrap', jquerytablesorter: 'libs/tablesorter/jquery.tablesorter', tablesorter: 'libs/tablesorter/tables', ajaxupload: 'libs/ajax-upload', templates: '../templates' }, shim: { 'backbone': { deps: ['underscore', 'jquery'], exports: 'Backbone' }, 'jquery': { exports: '$' }, 'bootstrap': { deps: ['jquery'], exports: '$' }, 'jquerytablesorter': { deps: ['jquery'], exports: '$' }, 'tablesorter': { deps: ['jquery'], exports: '$' }, 'ajaxupload': { deps: ['jquery'], exports: '$' }, 'underscore': { exports: '_' }, } }); require(['app', ], function(App) { App.initialize(); });
有魅力!!
解决这个问题
"styles": [ "src/styles.css", "node_modules/bootstrap/dist/css/bootstrap.min.css" ], "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" ]