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

A recent change in the release process breaks importing into typical typescript projects #1306

Closed
2 tasks done
ianwremmel opened this issue Aug 18, 2023 · 8 comments · Fixed by #1332
Closed
2 tasks done
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@ianwremmel
Copy link

Description

Somewhere between 6.4.0 and 6.5.0, openapi-typescript's internal types changed and the package can no longer be imported by projects that use "moduleResolution": "node". I've been trying to switch to "moduleResolution": "nodenext", but it's probably too strict to use for several years.

node_modules/openapi-typescript/dist/types.d.ts:1:23 - error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.

1 /// <reference types="node" resolution-mode="require"/>
                        ~~~~

node_modules/openapi-typescript/dist/index.d.ts:1:23 - error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.

1 /// <reference types="node" resolution-mode="require"/>
                        ~~~~

node_modules/openapi-typescript/dist/index.d.ts:2:23 - error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.

2 /// <reference types="node" resolution-mode="require"/>
                        ~~~~

Name Version
openapi-typescript 6.5.0
typescript 5.1.6
Node.js 18.17.0
OS + version macOS 13, Windows 11, etc.

Reproduction

How can this be reproduced / when did the error occur?

Install 6.5 or later, change moduleResolution to nodenext in tsconfig.json, and import from 'openapi-typescript' somewhere in your project.

Expected result

No errors from inside node_modules.

Checklist

  • My OpenAPI schema passes the Redocly validator (npx @redocly/cli@latest lint) Not Applicable
  • I’m willing to open a PR (see CONTRIBUTING.md) The URL is not found
@ianwremmel ianwremmel added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Aug 18, 2023
@drwpow
Copy link
Contributor

drwpow commented Aug 18, 2023

So 6.4.0 shipped the CJS bundle (#1263), but you’re saying 6.4.0 works, but not 6.5.0?

Agree moduleResolution: "NodeNext" shouldn’t be a requirement to use this package. It’s not realistically possible for most apps today.

@ianwremmel
Copy link
Author

but you’re saying 6.4.0 works, but not 6.5.0?

yep, that's correct. 6.4.0 seems to work just fine, but 6.5.0 causes that error. I'm not sure if it's 6.5 or one of the 6.4 point releases.

I skimmed the changelog, and nothing jumped out as a likely culprit, but I didn't look at code.

Agree moduleResolution: "NodeNext" shouldn’t be a requirement to use this package. It’s not realistically possible for most apps today.

Yea :) It made a lot of sense until I tried it and then import type broke everywhere for, in my opinion, invalid reasons 😂

So 6.4.0 shipped the CJS bundle

yep, thanks! I really appreciated that one:)

side note on it, the typescript folks seem to be formalizing a types key in exports, so changing this

"exports": {
    ".": {
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    },
    "./*": "./*"
  },

to this

"exports": {
    ".": {
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
      "types": "./dist/index.d.ts"
    },
    "./*": "./*"
  },

is one step towards making openapi-typescript compatible with nodenext, but I'm getting off topic and I really ought to open a separate issue.

@drwpow
Copy link
Contributor

drwpow commented Aug 18, 2023

the typescript folks seem to be formalizing a types key in exports

🤦 Oh shoot that should be there. That’s just an oversight. You’re right probably not the central issue here, but that’s a quick-and-easy fix regardless.

@ianwremmel
Copy link
Author

Sorry, I just realized it's not a recent change. A recent change broke the local patch that I have to address the issue 🤦‍♂️. I originally patched locally against 6.3.9, so the issue is at least that old.

@drwpow
Copy link
Contributor

drwpow commented Aug 18, 2023

Ah OK that makes more sense! 6.4.0 was my initial suspect and it seems that is probably where the breakage happened. Will start investigating there.

@ianwremmel
Copy link
Author

I'm confident I originally ran into this with 6.3.9, based on this patchfile I found :)
Screenshot 2023-08-18 at 12 24 55 PM

@ianwremmel
Copy link
Author

ianwremmel commented Aug 18, 2023

I bet it's this commit which switched tsconfig to use NodeNext

@drwpow
Copy link
Contributor

drwpow commented Sep 8, 2023

Sorry this took a little bit to dig into further. Just reverted this behavior; next patch version will restore the .d.ts files back to what they were. This entire rabbithole is such an opaque, confusing behavior of TypeScript 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants