openapi-contrib / openapi-schema-to-json-schema

Due to the OpenAPI v3.0 and JSON Schema discrepancy, you can use this JS library to convert OpenAPI Schema objects to proper JSON Schema.
https://www.npmjs.com/package/@openapi-contrib/openapi-schema-to-json-schema
MIT License
242 stars 20 forks source link

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Gsharma\Documents\test\node_modules\lodash-es\lodash.js from C:\Users\Gsharma\Documents\test\node_modules\@openapi-contrib\openapi-schema-to-json-schema\dist\cjs\lib\converters\schema.js not supported. #53

Closed thegauravsharma closed 1 year ago

thegauravsharma commented 1 year ago

I am using Loopback 4 CLI to connect Microsoft SQL database in my app, after adding data source getting following errors. I've already tried to install lodash-es in package.json but not helping. Please review the following error and help me out.

Thanks

C:\Users\Gsharma\Documents\test\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 C:\Users\Gsharma\Documents\test\node_modules\lodash-es\lodash.js from C:\Users\Gsharma\Documents\test\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 C:\Users\Gsharma\Documents\test\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. (C:\Users\Gsharma\Documents\test\node_modules\@openapi-contrib\openapi-schema-to-json-schema\dist\cjs\lib\converters\schema.js:8:21) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@openapi-contrib\openapi-schema-to-json-schema\dist\cjs\lib\convert.js:7:34) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@openapi-contrib\openapi-schema-to-json-schema\dist\cjs\index.js:8:19) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@loopback\rest\dist\validation\request-body.validator.js:14:22) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@loopback\rest\dist\parser.js:15:34) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@loopback\rest\dist\index.js:32:22) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@loopback\rest-explorer\dist\rest-explorer.component.js:10:16) at Object. (C:\Users\Gsharma\Documents\test\node_modules\@loopback\rest-explorer\dist\index.js:18:22) at Object. (C:\Users\Gsharma\Documents\test\dist\application.js:6:25) at Object. (C:\Users\Gsharma\Documents\test\dist\index.js:6:23)

fidgi commented 1 year ago

@thegauravsharma Add "overrides": { "@openapi-contrib/openapi-schema-to-json-schema": "3.2.0" }, to your package.json as a temporary workaround

rodcts commented 1 year ago

For me these question can be answered quite simply include into package.json "@openapi-contrib/openapi-schema-to-json-schema": "3.2.0".

No more and successful!!

mgabeler-lee-6rs commented 1 year ago

46 broke this. Despite bdac387ce9901898e59c41fa4d2c2041e938d474 being tagged as BREAKING and the blame commit for this, that commit for some reason doesn't show up in #46, which was released as a feature bump instead of a major version bump.

While that PR claims it added esm and cjs builds, it hard codes use of esm dependencies which make the cjs builds unusable. Clearly more CI testing is needed as this seems like the kind of thing that could have trivially been caught in a basic CI test, since you can't even require() the cjs build of 3.3.0.

agnes512 commented 1 year ago

Seeing the same issue

abdoadel123 commented 1 year ago

I think this error is happening on Linux only but this solution works for me

"overrides": { "@openapi-contrib/openapi-schema-to-json-schema": "3.2.0" },

litinskii commented 1 year ago

Same error

shubhamp-sf commented 1 year ago

Duplicate of https://github.com/openapi-contrib/openapi-schema-to-json-schema/issues/54.

Seems to be fixed starting v3.3.1

jonluca commented 1 year ago

Should be fixed in 3.3.1, let me know if anyone is still seeing issues

There is the issue where the built cjs now has exports.default = openapiSchemaToJsonSchema instead of module.exports = openapiSchemaToJsonSchema, which might cause issues if people are using a default import in cjs.

jonluca commented 1 year ago

As a follow up to this - I'll be releasing a new change, 3.3.2, which is the old version of the code from 3.2.0, and then create an actual breaking change with a release to 4.0.0. Apologies for the breakage here everyone.

shubhamp-sf commented 1 year ago

+1 for the old version to be available as the latest in series 3.x.x. Thanks @jonluca for the quick fix.

jonluca commented 1 year ago

Ok 3.3.2 should be pushed and live. This should fix any packages dependent on 3.x. Creating a 4.x cut right now. Apologies I didn't catch this sooner, again.