I am trying to use react-vis library in my project. In their readme file, they have asked to import library by adding following lines in non-node environment:
If you're working in a non-node environment, you can also directly include the bundle and compiled style using basic html tags.
<link rel="stylesheet" href="https://unpkg.com/react-vis/dist/style.css"> <script type="text/javascript" src="https://unpkg.com/react-vis/dist/dist.min.js"></script>The global
reactVisobject will now be available for you to play around.
When I did that, I got following error:
Uncaught TypeError: Cannot call a class as a function
at _classCallCheck (dist.min.js:formatted:23789:27)
at LabelSeries (dist.min.js:formatted:23823:21)
at Constructor.render (<anonymous>:1866:23)
at Constructor.<anonymous> (react.js:6029:34)
at Constructor._renderValidatedComponent (react.js:11403:21)
at Constructor.<anonymous> (react.js:5582:14)
at Constructor.mountComponent (react.js:11403:21)
at Constructor.mountChildren (react.js:10913:42)
at Constructor._createContentMarkup (react.js:6812:32)
at Constructor.<anonymous> (react.js:6734:14)
After a lot of digging, I realised issue was that the react-vis library follows ES6, while my project is in ES5. So, I thought to transpile react-vis library to ES5. After digging a bit in the react-vis repo, I found that it uses browserify.
So to compile ES6 porject to single ES5 bundle file using browserify itself, I added --presets [ @babel/preset-env ] on this line itself as suggested here:
"build:browser": "browserify src/index.js -t [ babelify --presets [ @babel/preset-env ] ] --standalone reactVis | uglifyjs > dist/dist.min.js",
I also tried adding @babel/preset-react:
"build:browser": "browserify src/index.js -t [ babelify --presets [ @babel/preset-env @babel/preset-react] --rootMode upward ] --standalone reactVis | uglifyjs > dist/dist.min.js",
But in both cases I ended up getting same error: Cannot call a class as a function.
What I am missing?