hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
221 stars 21 forks source link

TypeError: Cannot read properties of undefined (reading 'match') #20

Closed csdebruin closed 1 year ago

csdebruin commented 1 year ago
async function run(){
    console.log('\n\n<------------------------------ Starting\n')

    const
        JsonSchema = require("@hyperjump/json-schema"),
        schemaJson = {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "$id": "http://example.com/schemas/string",
            "type": "string"
        }

    const output = await JsonSchema.validate(schemaJson, "foo");

    console.log(output)
}

run()

Produces output:

<------------------------------ Starting

C:\path\to\jsonschema\node_modules\uri-js\dist\es5\uri.all.js:874
    var matches = uriString.match(URI_PARSE);
                            ^

TypeError: Cannot read properties of undefined (reading 'match')
    at parse (C:\path\to\jsonschema\node_modules\uri-js\dist\es5\uri.all.js:874:29)
    at Object.resolve (C:\path\to\jsonschema\node_modules\uri-js\dist\es5\uri.all.js:1124:75)
    at resolveUrl (C:\path\to\jsonschema\node_modules\@hyperjump\json-schema-core\lib\common.js:17:27)  
    at Object.get (C:\path\to\jsonschema\node_modules\@hyperjump\json-schema-core\lib\schema.js:193:23) 
    at compileSchema (C:\path\to\jsonschema\node_modules\@hyperjump\json-schema-core\lib\core.js:112:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async compile (C:\path\to\jsonschema\node_modules\@hyperjump\json-schema-core\lib\core.js:33:21)
    at async Object.validate (C:\path\to\jsonschema\node_modules\@hyperjump\json-schema-core\lib\core.js:25:20)
    at async run (C:\path\to\jsonschema\index.js:14:20)

With the following package.json:

{
  "name": "y",
  "version": "1.0.0",
  "description": "JSONSchema experiment",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@hyperjump/json-schema": "^0.23.3"
  }
}
jdesrosiers commented 1 year ago

This is a duplicate of #19. It's blowing up because you're not using the library correctly. See the linked issue for the explanation.