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

Cannot import oas31 using ESM in openapi3-ts@4.1.1 #114

Closed
invakid404 opened this issue Apr 18, 2023 · 5 comments · Fixed by #117
Closed

Cannot import oas31 using ESM in openapi3-ts@4.1.1 #114

invakid404 opened this issue Apr 18, 2023 · 5 comments · Fixed by #117

Comments

@invakid404
Copy link

invakid404 commented Apr 18, 2023

While trying to upgrade to openapi3-ts@4.1.1 in my project, I suddenly started getting this error on all my imports:

import { oas31 } from 'openapi3-ts';
         ^^^^^
SyntaxError: Named export 'oas31' not found. The requested module 'openapi3-ts' 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';
const { oas31 } = pkg;

I'm guessing this is happening because my project is ESM. It used to work fine with openapi3-ts@4.0.4.

I'm using TypeScript 5.0.4, and my tsconfig.json looks like this:

{
  "compilerOptions": {
    "lib": ["ESNext", "dom"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "resolveJsonModule": true,
    "outDir": "dist"
  }
}
@koooge
Copy link
Contributor

koooge commented Apr 18, 2023

Hi,
"moduleResolution": "node16", would work. We need to update the README.

refs: #111

@invakid404
Copy link
Author

What if I want to use NodeNext though? Switching to Node16 is not an option for my project.

@koooge
Copy link
Contributor

koooge commented Apr 18, 2023

You can use it since it is the exact same. https://www.typescriptlang.org/tsconfig#moduleResolution

@invakid404
Copy link
Author

But if it's the exact same, why wouldn't it work in the first place? I'm confused :D

@koooge
Copy link
Contributor

koooge commented Apr 19, 2023

Yours is not nodenext -> "moduleResolution": "Node",.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants