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

Cannot use schema validate from ajv #142

Closed
kamontat opened this issue Feb 6, 2021 · 2 comments
Closed

Cannot use schema validate from ajv #142

kamontat opened this issue Feb 6, 2021 · 2 comments

Comments

@kamontat
Copy link
Contributor

kamontat commented Feb 6, 2021

Problem

The generated code on schema section is below

shot-07_02_2021-00_18_46

const ajv_1 = require("ajv");

if (options.schema) {
    if (typeof options.schema !== 'object') {
        throw new TypeError('The `schema` option must be an object.');
    }
    const ajv = new ajv_1.default({ // problem from here
        allErrors: true,
        useDefaults: true
    });
    const schema = {
        type: 'object',
        properties: options.schema
    };
    __classPrivateFieldSet(this, _validator, ajv.compile(schema));
    for (const [key, value] of Object.entries(options.schema)) {
        if (value === null || value === void 0 ? void 0 : value.default) {
            __classPrivateFieldGet(this, _defaultValues)[key] = value.default;
        }
    }
}

it add .default after require ajv from node_modules but when ajv export, it didn't use any default key as screenshot below

shot-07_02_2021-00_24_52

So now it throw TypeError: ajv_1.default is not a constructor error.

P.S I use this via electron-store library

Version

conf: version 9.0.0
os: Macos version 11.1 (20C69) Big Sur
node: v15.5.1
yarn: v1.22.10

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 6, 2021

I just npm install ajv and it does have a .default property. You are looking at the lib folder, while you need to look at dist.

@kamontat
Copy link
Contributor Author

kamontat commented Feb 6, 2021

shot-07_02_2021-00_37_31

I should see on lib, because it specify main file to lib/ folder

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

2 participants