简体   繁体   中英

webpack: Tether is not defined

I'm creating a WebExtension, I need to use the selection-menu library in my content.js. It has in tether dependencies, so I installed:

npm install tether
npm install selection-menu

Then in my code I write:

import * as Tether from 'tether'
import SelectionMenu from 'selection-menu'

...
    this.selection_menu = new SelectionMenu({
      container: document.body,
      content: '<button> click me </button>',
      onselect: function(e) {
        this.menu.innerHTML = 'Selection length: ' + this.selectedText.length;
      }
    });

but when I select text, I get an error:

VM1492:23 Uncaught ReferenceError: Tether is not defined
    at i.show (<anonymous>:23:2899)
    at <anonymous>:23:4192

but in the page code I see that tether was imported 屏幕

how to fix this error?

This work for me:

in my webpack.config.js:

config.plugins = (config.plugins || []).concat([
...
  new webpack.ProvidePlugin({
    tether: 'tether',
    Tether: 'tether',
    'window.Tether': 'tether',
  })
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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