Skip to content

Invalid Validator Typescript file generated - Require used outside of import statement #56

@wjs4572

Description

@wjs4572

The last statement in the following code block contains the require that is causing the issue. It could be fixed by adding an import statement and than assigning that value to the ajv.addMetaSchema() calll.

The generated file:

// generated by typescript-json-validator
import {inspect} from 'util';
import Ajv = require('ajv');
import ourReportfrom './ourReport';
export const ajv = new ajv({"allErrors":true,"coerceTypes":false,"format":"fast","nullable":true,"unicode":true,"uniqueItems":true,"useDefaults":true});

ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));

update:

The following error doesn't like the node_modeuls so the fix doesn't work. Not sure how to fix this yet.

  TS6059: File ' _PACKAGE_PATH_\node_modules\ajv\lib\refs\json-schema-draft-06.json' is not under 'rootDir' ' _PACKAGE_PATH_/src'. 'rootDir' is expected to contain all source files.

update:
Temp work-around ->
/* eslint-disable @typescript-eslint/no-var-requires */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions