Javascript jQuery 未在引导模块中定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28393674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:44:07  来源:igfitidea点击:

jQuery not define in bootstrap module

javascriptnode.jstwitter-bootstrap

提问by LLenain

I want to use bootstrap for my website (with node.js). But I have the following error :

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

/var/www/node_modules/bootstrap/js/transition.js:59 }(jQuery); ^ ReferenceError: jQuery is not defined at Object. (/var/www/node_modules/bootstrap/js/transition.js:59:3) 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. (/var/www/node_modules/bootstrap/dist/js/npm.js:2:1) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10)

/var/www/node_modules/bootstrap/js/transition.js:59 }(jQuery); ^ ReferenceError: jQuery 未在 Object 中定义。(/var/www/node_modules/bootstrap/js/transition.js:59:3) 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) 在对象。(/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)

I tried to do a

我试着做一个

var bootstrap = require('bootstrap');

in my main node.

在我的主节点中。

I installed bootstrap with npm (npm install bootstrapfrom my folder). I also tried to instal jquery with the same way and to add a var jQuery= require('jquery');but it does not work. Do you have any idea what could be wrong ? I am starting node.js, i may miss something

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

Then I use <link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">in my HTML webpage to refer to bootstrap `

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

回答by xqwzts

To use jquery plugins with npm/node you need to set the global jQuery variable before requiring your plugin [bootstrap in this case]:

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

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

More details in this npm blog post

npm 博客文章中的更多详细信息