
I tried using Ajv in a React Native app, however I wasn't even able to include the module (see the screenshot). I tried the stable version, as well as 5.0.3-beta, same thing happens. I used the code example in the docs:
var Ajv = require('ajv');
var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
var validate = ajv.compile(schema);
var valid = validate(data);
if (!valid) console.log(validate.errors);
But like the error says, I wasn't able to validate anything, it was failing even before with the require('ajv') statement.
It says something about "url" module not found. It is a core node.js module that would also be available if you were to use browserify.
It also mentions https://github.com/facebook/react-native/issues/4968
As a workaround I can suggest using supplied bundle - it exports global Ajv.
Thanks!
@claudiorodriguez do you know how to solve it?
I have the same issue. Unable to resolve module 'url'.
var url = require('url');
Seems as if core nodejs modules are not available in react-native and not related to this module.
@nenti @pavlelekic I think including url module from npm as your app dependency can help. Please let me know if it does or doesn't.
@epoberezkin I can confirm that adding url as a dependency works.
@superandrew213 thank you
How do you add url as dependency of your React Native project?
@jsaucedo npm i --save url
Most helpful comment
@nenti @pavlelekic I think including url module from npm as your app dependency can help. Please let me know if it does or doesn't.