React application fails to build due to missing 'mirror' and 'Mirror' globals

#1

I’m attempting to integrate Estimote Mirror functionality into a React application, but cannot build a production version of the application due to not having access to the mirror and Mirror JavaScript globals. Are there any officially supported fixes for this situation?

Thanks.

#2

I’m not an React expert, but there should be a way for JS framework to access global/browser objects, because you may want to integrate your webpage with some browser APIs (WebBluetooth, MIDI, USB etc.) or other external libs. You need to check React documentation on this.
Have you tried to add this at the top of .js file?

/*global mirror*/
/*global Mirror*/

There is other way described here:


This may work since you can refer to mirror object as window.mirror.

#3

Note that the mirror and Mirror globals are only available when running on … well, Mirror (:

If for some reason your build scripts need to run the code locally on your computer, you may need to mock these objects.

#4

Thanks for all of the help. I’ve managed to trick the compiler into working by destructuring the global variables like so:

const { mirror, Mirror } = window;

I hesitated with this approach as I was unsure if Mirror was stored on the window global. Fingers crossed that the API works as intended now!

1 Like