【问题标题】:jQuery not define in bootstrap modulejQuery 没有在引导模块中定义
【发布时间】:2015-04-08 05:49:05
【问题描述】:

我想为我的网站使用引导程序(使用 node.js)。但我有以下错误:

/var/www/node_modules/bootstrap/js/transition.js:59 }(jQuery); ^ ReferenceError:未定义 jQuery 在对象。 (/var/www/node_modules/bootstrap/js/transition.js:59:3) 在 Module._compile (module.js:456:26) 在 Object.Module._extensions..js (module.js:474:10) 在 Module.load (module.js:356:32) 在 Function.Module._load (module.js:312:12) 在 Module.require (module.js:364:17) 在需要 (module.js:380:17) 在对象。 (/var/www/node_modules/bootstrap/dist/js/npm.js:2:1) 在 Module._compile (module.js:456:26) 在 Object.Module._extensions..js (module.js:474:10)

我试着做一个

var bootstrap = require('bootstrap');

在我的主节点中。

我用 npm 安装了引导程序(npm install bootstrap 来自我的文件夹)。我还尝试以相同的方式安装 jquery 并添加var jQuery= require('jquery');,但它不起作用。你知道有什么问题吗?我正在启动 node.js,我可能会错过一些东西

然后我在我的 HTML 网页中使用<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> 来引用引导程序 `

【问题讨论】:

  • 你在引导之前加载 jquery 吗?
  • 是的,我做了一个var jQuery = require('jquery');var bootstrap = require('bootstrap');

标签: javascript node.js twitter-bootstrap


【解决方案1】:

要将 jquery 插件与 npm/node 一起使用,您需要在需要插件之前设置全局 jQuery 变量[在这种情况下为引导程序]:

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

npm blog post 中的更多详细信息

【讨论】:

  • 谢谢!我喜欢它,我不必垫片这个和垫片!
  • @Amjad 您是指专门的引导程序还是其他一些 jQuery 插件?你得到什么错误?我使用 bootstrap 3.3.2 的初始化代码是:var $ = require('jquery'); global.jQuery = $; require('bootstrap'); require('malihu-custom-scrollbar-plugin')($);,这对我来说很好......
  • 当我尝试这个解决方案时,我收到错误“TypeError: Cannot set property 'emulateTransitionEnd' of undefined”
  • 我得到同样的错误“TypeError: Cannot set property 'emulateTransitionEnd' of undefined”
  • 我遇到了同样的错误... TypeError: Cannot set property 'emulateTransitionEnd' of undefined
猜你喜欢
  • 2021-12-23
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 1970-01-01
  • 2016-05-15
  • 2019-09-09
  • 2016-08-29
  • 1970-01-01
相关资源
最近更新 更多