Uncaught (in promise) TypeError: $ is not a function

Uncaught (in promise) TypeError: $ is not a function

我正在尝试使用 material design lite 显示带有波纹的按钮,但出现以下错误:

app.js:3 Uncaught (in promise) TypeError: $ is not a function(…)

html 文件:

  <body>
      <script>
System.paths['jquery'] = './node_modules/jquery/dist/jquery.js';
              System.import('src/app.js');
</script> 
  </body>

app.js:

      import $ from 'jquery';
import {Button} from './ui/button.js';
let b=new Button('click me');
b.appendToElement($('body'));

button.js :

      import {BaseElement} from './base-element.js';

export class Button extends BaseElement {

    constructor(title) {
        super();
        this.title = title;
}

    getElementString() {
        return `
            <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"
                style="">
                ${this.title}
            </button>
        `;
    }

}

基础-element.js:

    import $ from 'jquery';

export class BaseElement {

    constructor() {
        this.element = null;  // jQuery object
    }

    appendToElement(el) {
        this.createElement();
        el.append(this.element);
}

    createElement() {
        let s = this.getElementString();
        this.element = $(s);
    }

    getElementString() {
        throw 'Please override getElementString() in BaseElement';
    }
}

由于 jQuery 将自身附加到您应该使用的全局对象 import 'jquery'

在默认导出 'jquery' 的全局对象上使用 import $ from 'jquery' 阴影 $,但 jQuery 不导出任何内容,因此 $ === undefined .