使用Bootstrap&带有Browserify的ES6中的jQuery包 [英] Error using Bootstrap & jQuery Packages in ES6 with Browserify

查看:149
本文介绍了使用Bootstrap&带有Browserify的ES6中的jQuery包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 引导 jQuery 。我正在使用 浏览版 ,使用 Babel 转换为编译。我收到以下错误。

 未捕获ReferenceError:未定义jQuery 

我尝试导入这样的包,但是我收到上述错误。

 $ code> import'from'jquery'; 
导入Bootstrap从'bootstrap';

搜索到,我发现 此答案 ,所以我尝试了这个,但我仍然收到相同的错误。

  import'from'jquery'; 
window。$ = window.jQuery = $;
导入Bootstrap从'bootstrap';
Bootstrap。$ = $;我输入这些软件包是不正确的ES6还是用不同的方式完成?我尝试的最后一件事是导入没有这样的ES6的包,但我仍然有相同的错误。

 窗口$ = window.jQuery = require('jquery'); 
var Bootstrap = require('bootstrap');
Bootstrap $ = $


解决方案

如上所述 皮特TNT ,有一个 错误 。我切换到使用 此Bootstrap软件包 ,并进行以下操作更改我的代码。

 窗口$ = window.jQuery = require('jquery'); 
var Bootstrap = require('bootstrap-sass');
Bootstrap。$ = $;
require('../../../../../ node_modules / bootstrap-sass / assets / javascripts / bootstrap');

看起来,暂时是ES6 import s将无法使用 jquery bootstrap 包,以我试图使用它们的方式。 / p>

I'm trying to use Bootstrap with jQuery. I'm using Browserify with a Babel transform to compile. I get the following error.

Uncaught ReferenceError: jQuery is not defined

I've tried importing the packages like this, but I get the above error.

import $ from 'jquery';
import Bootstrap from 'bootstrap';

Searching around, I found this answer, so I tried this but I still get the same error.

import $ from 'jquery';
window.$ = window.jQuery = $;
import Bootstrap from 'bootstrap';
Bootstrap.$ = $;

Am I importing these packages incorrectly with ES6 or is it done in a different way? The last thing I tried was importing the packages without ES6 like this, but I still got the same error.

window.$ = window.jQuery = require('jquery');
var Bootstrap = require('bootstrap');
Bootstrap.$ = $

解决方案

As mentioned by Pete TNT, there is a bug in the Bootstrap package I am using. I switched to using this Bootstrap package and made the following changes to my code.

window.$ = window.jQuery = require('jquery');
var Bootstrap = require('bootstrap-sass');
Bootstrap.$ = $;
require('../../../../../node_modules/bootstrap-sass/assets/javascripts/bootstrap');

It looks like, for the time-being, ES6 imports will not work with jquery and bootstrap packages in the way I was trying to use them.

这篇关于使用Bootstrap&带有Browserify的ES6中的jQuery包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆