Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wjs4572 opened this issue Dec 1, 2021 · 0 comments

Comments

@wjs4572
Copy link

wjs4572 commented Dec 1, 2021

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 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant