-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: Export ./oas30 and ./oas31 #111
Conversation
Signed-off-by: koooge <koooooge@gmail.com>
it does not work with ESM now
|
"./oas30": { | ||
"import": "./dist/mjs/oas30.js", | ||
"require": "./dist/cjs/oas30.js" | ||
}, | ||
"./oas31": { | ||
"import": "./dist/mjs/oas31.js", | ||
"require": "./dist/cjs/oas31.js" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually my build fails to make DTS with such imports
src/open-api.ts(8,8): error TS2307: Cannot find module 'openapi3-ts/oas30' or its corresponding type declarations.
Error: error occured in dts build
DTS Build error
RollupError: Failed to compile. Check the logs above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is not right with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess your tsconfig.json has moduleResolution: "node" which cannot resolve the exports field. As one option, node16 would work tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is.
Could you tell me please, @koooge , does it mean, that the minimum Node version of my package (that depends on openapi3-ts
) should be upgraded from 14 to 16 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say node version does not matter. It is due to the config of typescript. If you use tsc with "moduleResolution": "node"
, this approach would not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Thank you.
But there is another problem.
Still, my ESM setup does not work with the following error regarding ./oas30
import:
SyntaxError: Named export 'isReferenceObject' not found. The requested module 'openapi3-ts/oas30' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'openapi3-ts/oas30';
I use ts-node-esm
command (of ts-node
) as a runner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It thinks that /oas30
is CommonJS, @koooge .
It can be fixed by placing package.json
file inside ./dist/mjs
having {"type": "module"}
.
However, it does not end on it. It can not find files being imported by oas30.js
withing having .js
extensions in the import statements. I believe the ESM build should actually have the explicitly specified extensions. Probably the ESM compiler need to be configured. CC @pjmolina
However, this is a well-known issue, which I'm not sure what is the right solution to,
microsoft/TypeScript#16577 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because moduleResolution node(=node10) checks "main" in pckage.json. Use "moduleResolution": "node16"
or bundler as a workaround. For support tsc, we need to export only "." and create dist/oas30 & dist/oas31 I suppose.
Hi there, this is a proposal for import syntax for compatibility with v3 code. It is helpful since we can upgrade openapi3-ts without code changes like
oas31.OpenAPIObject
.Also, it would fix #107