ajv-validator / ajv-validator/ajv

in (Deno or browsers) and (skypack or esm.sh), standalone compilation fails on recursive schemas

未关闭
#1,850 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
compatibility
主要语言
TypeScript
星标
14.8k
派生
1k
PR 合并指标
30 天内没有已合并 PR

描述

This report appears specific to using (either of) skypack or esm.sh to get a ES6 module version of ajv. I see the issue in both Deno v1.16.4 and Chrome 96.0.4664.110 (on OS X, though I doubt that matters).

Specifically, a call to `safeStringify` in the codegen step appears to find a circular structure, causing the generation to fail. On node.js environments, that doesn't happen.

**The version of Ajv you are using**
8.8.2

**The environment you have the problem with**
Deno or browser, using the library as packaged by skypack, esm.sh.

**Your code (please make it as small as possible to reproduce the issue)**
A minimal example is here. This works on node 17, fails on Deno 1.16
https://runkit.com/cscheid/ajv-non-issue

**Results in node.js v8+**
In node.js, the standalone source is generated without a problem.

**Results and error messages in your platform**
There is a runtime error:

```
> const moduleSrc = standalone(ajv, { "navigation-item": "navigation-item" })
--> starting at object with constructor 'SchemaEnv'
| property 'refs' -> object with constructor 'Object'
--- property 'navigation-item' closes the circle
at JSON.stringify ()
at safeStringify (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:138:17)
at interpolate (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:131:78)
at addCodeArg (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:91:17)
at Object._ (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:66:7)
at refValidateCode (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/standalone/index.js:63:35)
at https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:287:76
at Set.forEach ()
at ValueScope._reduceValues (https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:279:12)
at ValueScope.scopeCode (https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:266:19)
```

I suspect the answer here to be that there's a miscompilation somewhere in both esm.sh and skypack.dev. It is somewhat unfortunate, though, because ajv itself works excellently in skypack. It would be fantastic to be able to work around this issue if anyone knows how to do that.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。