-1

I am trying to incorporate the JSON Schema validator ajv into a Polymer 2.0 component. It can be loaded with npm

npm install ajv

I am having a problem instantiating ajv within a Polymer 2.0 component.

Accessing ajv is done through the require:

var Ajv = require('ajv');
var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
var validate = ajv.compile(schema);

How do I incorporate ajv within my Polymer 2.0 element?

Loren Cahlander
  • 1,257
  • 1
  • 10
  • 24

1 Answers1

0

I found my answer. It is at https://github.com/epoberezkin/ajv/issues/21. I needed to use browserify.

npm install -g browserify

browserify -r ./node_modules/ajv/lib/ajv.js:ajv -o ./node_modules/ajv/lib/bundle.js

In the html file:

<script src="../../node_modules/ajv/lib/bundle.js"></script>
<script>
  Ajv                  = require('ajv')
  , ajv                  = Ajv();
</script>
Loren Cahlander
  • 1,257
  • 1
  • 10
  • 24