generator: Doc generation broken using json file is broken due to upstream ESM/CJS changes
Describe the bug
Doc generation broken using json file is broken. This appears to be due to a new upstream release https://github.com/openapi-contrib/openapi-schema-to-json-schema/releases/tag/v3.3.0
How to Reproduce
Repo with minimal reproducible bug:
https://github.com/hrkeni/asyncapi-generator-esm-bug
Clone and run npm run gen-docs
> test@1.0.0 gen-docs
> ag asyncapi.json @asyncapi/html-template --force-write -o ./public
/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js:8
const lodash_es_1 = require("lodash-es");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/keni/oss/asyncapi-generator-esm-bug/node_modules/lodash-es/lodash.js from /home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js not supported.
Instead change the require of lodash.js in /home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/converters/schema.js:8:21)
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/lib/convert.js:7:34)
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@openapi-contrib/openapi-schema-to-json-schema/dist/cjs/index.js:8:19)
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@asyncapi/openapi-schema-parser/index.js:1:22)
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@asyncapi/generator/lib/generator.js:10:29)
at Object.<anonymous> (/home/keni/oss/asyncapi-generator-esm-bug/node_modules/@asyncapi/generator/cli.js:8:19) {
code: 'ERR_REQUIRE_ESM'
}
Expected behavior
Dependencies should be resolved correctly
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 7
- Comments: 16 (8 by maintainers)
This error is causing issues with our build pipeline as well. Hoping it is solved fast!
@M3lkior yeah, pipelines hiccups. Fix on the way https://github.com/asyncapi/openapi-schema-parser/pull/170
npx
can ignore the lock file (sometimes), the local npm cache and the globally installed modules. The core value proposition ofnpx
(compared tonpm
) is that it can be run in whatever folder and context you want to without relying on additional files.https://www.npmjs.com/package/clear-npx-cache https://stackoverflow.com/questions/63510325/how-can-i-clear-the-central-cache-for-npx
Thanks for the issue!
Seems like we need to freeze v3.2: https://github.com/openapi-contrib/openapi-schema-to-json-schema/issues/54
It needs to be done in https://github.com/asyncapi/openapi-schema-parser
@hrkeni would you be able to do that?