-
Notifications
You must be signed in to change notification settings - Fork 1.3k
react-hotkeys production build causes runtime error #1455
Description
Hi! I'm using esbuild with the react-hotkeys npm library, and there is a runtime error I get when using the production build.
https://github.com/greena13/react-hotkeys
The issue might be within the library, but I wanted to confirm this here.
I created a simplified repository where this can be reproduced:
https://github.com/andrewvarga/esbuild-test
- Run
npm installand the prod build:npm run build:prod. - Open the result in
build/prod/index.html - Press cmd + shift on a mac
-> error:
Uncaught ReferenceError: KeysWithKeyUpHiddenByCmd is not defined
at keyupIsHiddenByCmd (app.bundle.js:7547)
This works fine using the dev build.
What I found is that in the production build of react-hotkeys, the variable KeysWithKeyUpHiddenByCmd is defined right before the function keyupIsHiddenByCmd in the same context so it's accessible from there:
for(var KeysWithKeyUpHiddenByCmd={Enter:!0,Backspace:!0,ArrowRight:!0,ArrowLeft:!0,ArrowUp:!0,ArrowDown:!0,CapsLock:!0},i=1;13>i;i++)KeysWithKeyUpHiddenByCmd["F".concat(i)]=!0;
function keyupIsHiddenByCmd(a){return 1===a.length||hasKey(KeysWithKeyUpHiddenByCmd,a)}However in the bundle file provided by esbuild the variable is defined in something which starts like this:
var init_react_hotkeys_production_min = __esm({
"node_modules/react-hotkeys/es/react-hotkeys.production.min.js"() {and the function keyupIsHiddenByCmd is defined in an outer scope so it doesn't have access to KeysWithKeyUpHiddenByCmd.
These 2 modules in the react-hotkeys repo are here:
https://github.com/greena13/react-hotkeys/blob/master/src/helpers/resolving-handlers/keyupIsHiddenByCmd.js
https://github.com/greena13/react-hotkeys/blob/master/src/const/KeysWithKeyUpHiddenByCmd.js
Given this, is it possible to detect the source of the problem, whether it's in react-hooks or maybe esbuild does something during bundling that breaks these references?