2

I installed Mousetrap through npm and have been trying to get Mousetrap.bindGlobal to work but this is the error it gives me

Uncaught TypeError: mousetrap__WEBPACK_IMPORTED_MODULE_13__.bindGlobal is not a function

This doesn't make sense because when I import mousetrap in my jsx file, vscode shows that the command is valid. Any help with this would be useful.

user5735224
  • 461
  • 1
  • 7
  • 16

1 Answers1

4

bindGlobal is in the TypeScript definition, but not in the NPM package. It's an extension.

You can see the documention here. You can either add the extension manually, or add it with NPM/Yarn. I couldn't find any official package, but this one seems to be working fine.

$ npm i mousetrap-global-bind
$ yarn add mousetrap-global-bind

To make it work, you need to add Mousetrap, then the extension.

import mousetrap from 'mousetrap';
import 'mousetrap-global-bind';
Enzo Innocenzi
  • 549
  • 4
  • 12