sindresorhus/conf

Cannot use schema validate from ajv

kamontat opened this issue · 2 comments

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

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.

shot-07_02_2021-00_37_31

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