I’m working on a an app which uses the create-react-app tool to manage the configuration of Babel and webpack. The front-end code runs fine both in development (react-scripts start) and production (react-scripts build). Adding in remotestorage.js works fine in development. However, after running react-scripts build, the built app fails to start, with the error:
Uncaught TypeError: Cannot call a class as a function
at e.exports (classCallCheck.js:3)
at new e (cachinglayer.ts:26)
at o.<anonymous> (createSuper.js:15)
at new o (indexeddb.ts:60)
at e.featuresLoaded (features.ts:204)
I’m pulling Remote Storage with import RemoteStorage from 'remotestoragejs'; so I believe Babel is transpiling the code.
Can anyone suggest an approach to resolving this? I could run react-scripts eject, and tinker with the Babel config, but I’m loathe to increase the time I spend on admin work.
I’d love to help, but I’m not familiar with create-react-app tbh.
As it works in development, but seems to have issues with additional transpilation being done on the already-transpiled source, I would try to find out how you can prevent the transpilation of imported modules in general.
Maybe someone else reading this has more experience with create-react-app?
I think I got the same error with an Ember app once. Ember has a config option to define the Browsers that should be supported by the build. It is using Browserslist for that.
Removing IE11 support for the production build fixed the error for me.
I’m not familiar with create-react-app, but maybe it has a similar config option.
Unfortunately, it doesn’t fix the issue. I’m currently pursuing the hypothesis that Babel doesn’t compile some aspects of TypeScript correctly, as there are several reported bugs along those lines.
Including Remote Storage as static scripts did get the production build to run, but tests would not. So, I ejected from create-react-app after all, and set Webpack to not use babel-loader on remotestorage: