question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 (<anonymous>)
    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 (<anonymous>)
    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 Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
olescommented, Jul 29, 2022

I too would love to use AJV with Deno.

I’ve tried hacking support for it with Deno Deploy without success, as AJV generates code, and Deno Deploy does not support that, it seems.

1reaction
epoberezkincommented, Dec 15, 2021

And thanks a lot for such detailed report!

Read more comments on GitHub >

github_iconTop Results From Across the Web

esm@v99 - Deno
A fast, global content delivery network for NPM packages with ES Module format. Import from URL. import React from "https://esm.sh/ ...
Read more >
Panva/jose: "JSON Web Almost Everything" - Morioh
Panva/jose: "JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, ...
Read more >
ECMAScript 6 Tools Awesome - DirDev.com
Acorn - A small, fast, JavaScript-based JavaScript parser with ES6 support, parses to SpiderMonkey AST format. esparse - ES6 parser written in ES6....
Read more >
Registries | Dev Cheatsheets - Michael Currin
Deno : https://cdn.skypack.dev/react?dts. ESM. esm.sh. A fast, global content delivery network for ES Modules. All modules are transformed to ESM by ...
Read more >
Do esm.sh and jspm.org follow the same approach regarding ...
No, JSPM is in fact adding browser compatibility polyfills. It's thought for a more general usability across JavaScript ecosystems, so Deno ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found