Computer-Vision with React

1.3k Views Asked by At

I'm trying to find a client-side computer-vision library that plays nicely with React. I've tried tracking.js and js-objectdetect but I can't import them into a standard React component without major efforts that are beyond my skills.

The problem with both these awesome libraries is that they are written as IIFE with no export statements e.g.

(function(){...})()

They are supposed to be imported as <script src = 'etc'> so I can't seem to just import them as normal and follow the API without getting

TypeError: foo.bah is not a constructor

I tried adding my own export statements but a can of worms exploded out of it!

Can anyone suggest a better approach?

2

There are 2 best solutions below

1
On

If you are using webpack you can try exports-loader to allow you using import syntax.

Here is some more info.

0
On

Here is a working implementation of tracking.js with React (using create-react-app)

https://github.com/howardkitto/react-tracking

The solution was provided by https://github.com/gaearon, here... https://github.com/facebookincubator/create-react-app/issues/2958