acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.08k stars 338 forks source link

No longer valid CommonJS import #796

Closed BrannenGH closed 5 days ago

BrannenGH commented 1 week ago

Hello,

With the recent update to 13.0.9, all my usages of swagger-typescript-api using CommonJS modules has broken.

For example, consider the following import:

const { generateApi } = require('swagger-typescript-api');

With the new version, this fails with:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/brann/Source/repos/swagger-common/node_modules/swagger-typescript-api/src/index.js from /Users/brann/Source/repos/swagger-common/index.js not supported.
Instead change the require of /Users/brann/Source/repos/swagger-common/node_modules/swagger-typescript-api/src/index.js in /Users/brann/Source/repos/swagger-common/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/brann/Source/repos/swagger-common/index.js:1:25) {
  code: 'ERR_REQUIRE_ESM'
}

Would it be possible to ship a version transpiled to CommonJS to NPM as well for backwards compatibility?

Thank you!

smorimoto commented 6 days ago

I have to say that using CJS in the 21.2 century is a bit silly, but I plan to publish as both ESM and CJS dual formats in a single NPM package in the next point release.

serrg commented 6 days ago

@smorimoto I fully understand that you want to move away from CJS but releasing breaking change as patch update (13.0.8 to 13.0.9) can cause quite a bit of trouble for others. In such case (when changes are backwards incompatible), it should be considered as new version entirely. Thanks!

smorimoto commented 5 days ago

@BrannenGH @serrg https://github.com/acacode/swagger-typescript-api/releases/tag/13.0.10