foxbike
foxbike

Reputation: 51

How to make a library compatible with a React Native project

I imported this library https://github.com/THCLab/oca.js-form-core in my React Native project but I get an error when instantiating const ocaJs = new OcaJs({});: Error: Automatic publicPath is not supported in this browser, js engine: hermes

The library is Node.js compatible (there is an example in the Github repository). However, it is packaged (npm) with webpack and I believe that the React Native project uses this package for import. That's the problem (i think - i'm a beginner in React Native). There are references to the DOM added by webpack. Is there any way to force the use of the Node.js build instead?

Upvotes: 5

Views: 695

Answers (1)

William Trevena
William Trevena

Reputation: 276

Have you tried specifying the publicPath explicitly as discussed in the answers to this question?

In general however, because React Native does not contain all the Core Node JS Modules, many libraries which are compatible with Node.js require polyfills to work in React Native. You can attempt to make a polyfill yourself by following a guide such as this. I have experienced mixed results with such methods, but I am far from an expert. From my experience, trying to create a polyfill can be a time consuming venture to pursue, and I would recommend first exploring whether or not a React Native library exists which can help you accomplish your objective.

Upvotes: 1

Related Questions