Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openapi-metadata] Support for CommonJS #2097

Open
1 task
acs opened this issue Jan 13, 2025 · 4 comments · Fixed by #2115
Open
1 task

[openapi-metadata] Support for CommonJS #2097

acs opened this issue Jan 13, 2025 · 4 comments · Fixed by #2115
Assignees
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library

Comments

@acs
Copy link

acs commented Jan 13, 2025

Description

Hi team!

We are trying to use openapi-metadata in a large TypeScript project which is based on CommonJS (we plan to migrate to ESM at some point but not yet). It seems that openapi-metadata does not support CommonJS (the TS compiler suggest to change 'moduleResolution' setting 'node16', 'nodenext', or 'bundler'.).

Do you plan to support CommonJS in openapi-metadata?

Than you for your effort and time in this great project

-- Alvaro

Proposal

Support CommonJS in openapi-metadata

Extra

@acs acs added enhancement New feature or request openapi-ts Relevant to the openapi-typescript library labels Jan 13, 2025
@kerwanp kerwanp linked a pull request Jan 23, 2025 that will close this issue
@kerwanp
Copy link
Contributor

kerwanp commented Jan 23, 2025

Hi @acs,

You are right openapi-metadata does not support CJS, there is in fact a legacy tsup.config.ts file but is not used anymore. We are directly using tsc.

I've opened a pull-request #2115. It would be great if you could build the library yourself and tell me if everything works as intended!

@kerwanp kerwanp self-assigned this Jan 23, 2025
@acs
Copy link
Author

acs commented Jan 27, 2025

Thanks guys! I have seen that this is already included in 0.2.0. We have added a task for testing it in Feb. I will report the results here. We are in a MVP testing tsoc and openapi-metadata for a large TS project.

@acs
Copy link
Author

acs commented Jan 28, 2025

@kerwanp trying to use openapi-metadata importing it with CommonJS we get the error:

Uncaught Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: 
	Package subpath './dist/decorators' is not defined by "exports" in 
		/Users/acs/devel/backend/node_modules/openapi-metadata/package.json

@kerwanp kerwanp reopened this Jan 28, 2025
@kerwanp
Copy link
Contributor

kerwanp commented Jan 28, 2025

@acs could you show me your require ?
It seems you are trying to import decorators using ./dist/decorators where it should just be ./decorators.

// Not good
const { ApiOperation } = require('openapi-metadata/dist/decorators')

// Good
const { ApiOperation } = require('openapi-metadata/decorators')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants