Ajv: Unable to resolve module url from node_modules/ajv/lib/compile/resolve.js

Created on 10 Mar 2017  路  10Comments  路  Source: ajv-validator/ajv

simulator screen shot mar 10 2017 15 46 54
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.

compatibility

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.

All 10 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

busticated picture busticated  路  6Comments

dci-aloughran picture dci-aloughran  路  5Comments

JonathanWilbur picture JonathanWilbur  路  3Comments

mhelvens picture mhelvens  路  5Comments

radio-miskovice picture radio-miskovice  路  6Comments