如何解决错误“无法在Bootstrap node.js应用程序中设置属性'undefined undefined'的emulateTransitionEnd?

我从零开始创build了Node.js应用程序,并且已经添加到了app.js.

global.jQuery = require('jquery'); 

之后,它给了我错误如下:

 /home/yojna/web/node_modules/bootstrap/js/transition.js:36 $.fn.emulateTransitionEnd = function (duration) { ^ TypeError: Cannot set property 'emulateTransitionEnd' of undefined at /home/yojna/web/node_modules/bootstrap/js/transition.js:36:29 at Object.<anonymous>(/home/yojna/web/node_modules/bootstrap/js/transition.js:59:2) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/yojna/web/node_modules/bootstrap/dist/js/npm.js:2:1) at Module._compile (module.js:456:26) yojna@yojna-Inspiron-7520:~/web$ 

NPM被包括在服务器端库中。 要包含引导程序或jquery等客户端库,请使用Bower 。

我已经在expressjs应用程序中完成了这个工作:

  1. 创build一个.bowerrc文件并写入以下几行:

    {“directory”:“public / components”}

  2. 用Bower下载bootstrap和jquery:

    凉亭安装bootstrap

  3. 然后,在你的app.js文件中定义你的公共文件夹是静态的:

    app.use(express.static(__ dirname +'/ public'));

  4. 最后,在你的视图中添加脚本标签(我在这里使用Jade):

    脚本(src ='components / jquery / dist / jquery.min.js')脚本(src ='components / bootstrap / dist / js / bootstrap.min.js')

尝试申报美元符号variables:

 global.jQuery = global.$ = require('jquery'); 

我有这个问题,这是因为我已经包含在我的供应商webpack 2configuration“引导”,但使用:

 require("bootstrap-loader"); 

所以浏览器无法正确findbootstrap-loader软件包。

你不应该require 。 Jquery是一个客户端库,而Node.js是一个后端服务器。

如果你想用你的Node.js应用程序使用Jquery,只需将它添加到你的HTML文件中:

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>