ajv-validator / ajv-validator/ajv-errors

Unable to use package in browser

未關閉
#158 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
289
分支
21
PR 合併指標
30 天內沒有已合併 PR

描述

The following simple example works in NodeJS

```
import Ajv from 'ajv';
import ajvErrors from 'ajv-errors';

const ajv = new Ajv({
allErrors: true,
});

ajvErrors(ajv);

const schema = {
type: 'object',
properties: {
myFieldA: {
type: 'integer',
},
myFieldB: {
type: 'string',
},
},
errorMessage: {
properties: {
myFieldA: 'My Error Message 1',
myFieldB: 'My Error Message 2',
},
}
}

const submittedData = {
myFieldA: 'Hello World',
myFieldB: 1,
};

ajv.validate(schema, submittedData)

console.log(ajv.errors);
```

But the following simple example which is the same as the above example except it imports the package from a CDN, does not work

```

import Ajv from 'https://esm.sh/ajv@8.17.1';
import ajvErrors from 'https://esm.sh/ajv-errors@3.0.0';

const ajv = new Ajv({
allErrors: true,
});

ajvErrors(ajv);

const schema = {
type: 'object',
properties: {
myFieldA: {
type: 'integer',
},
myFieldB: {
type: 'string',
},
},
errorMessage: {
properties: {
myFieldA: 'My Error Message 1',
myFieldB: 'My Error Message 2',
},
}
}

const submittedData = {
myFieldA: 'Hello World',
myFieldB: 1,
};

ajv.validate(schema, submittedData);

console.log(ajv.errors);

```

I did the same thing to get `ajv-keywords`, `ajv-formats` packages to work in the browser by using esm.sh CDN. However I am unable to get `ajv-errors` to work.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。