简体   繁体   English

ES6 + jasny-bootstrap - 错误:找不到模块jasny-bootstrap?

[英]ES6 + jasny-bootstrap - Error: Cannot find module jasny-bootstrap?

How can I import jasny-bootstrap into my ES6 class? 如何将jasny-bootstrap导入我的ES6类?

ES6: ES6:

'use strict';

import $ from 'jquery';
import jasny from 'jasny-bootstrap';

class PushMenu {
    constructor() {
        this.slideShown = false;
        $('.navmenu').on('shown.bs.offcanvas', () => {
            this.slideShown = true;
        });
    }
}

I get an error when I try to compile it with gulp: 当我尝试使用gulp编译它时出错:

{ Error: Cannot find module 'jasny-bootstrap' from '/var/www/my-project/js'

I am sure I have already installed it with npm following its npm page : 我确信我已经在npm页面后面的npm安装了它:

npm install jasny-bootstrap

Any ideas why and how to resolve this? 任何想法为什么以及如何解决这个问题?

EDIT: 编辑:

I managed to load it manually with the full path: 我设法用完整路径手动加载它:

import jasny from '../node_modules/jasny-bootstrap/dist/js/jasny-bootstrap';

But it does not work with no error hinted. 但它工作,没有错误暗示。

EDIT 2: 编辑2:

I have tried to glue it with: 我试着把它粘在一起:

jQueryBridget('jasny', Jasny, $); 

but still no luck. 但仍然没有运气。 Error: 错误:

Uncaught TypeError: Cannot read property 'option' of undefined 未捕获的TypeError:无法读取未定义的属性“选项”

The entire code: 整个代码:

'use strict';

import $ from 'jquery';
import bootstrap from 'bootstrap';
import Jasny from '../node_modules/jasny-bootstrap/dist/js/jasny-bootstrap.js';
import jQueryBridget from 'jquery-bridget';

jQueryBridget('jasny', Jasny, $);

class PushMenu {
    constructor() {
        this.slideShown = false;
        $('.navmenu').on('shown.bs.offcanvas', () => {
            this.slideShown = true;
        });
    }
}

It does not work with ES6 import but works with: 它不适用于ES6 import但适用于:

<script src="vendor/jasny-bootstrap/jasny-bootstrap.js"></script>

Then without importing it: 然后不导入它:

class PushMenu {
    constructor() {
        this.slideShown = false;
        $('.navmenu').on('shown.bs.offcanvas', () => {
            this.slideShown = true;
        });
    }
}

Not ideal. 不理想。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM