swagger-typescript-api: type: module & moduleResolution: NodeNext fails if the Typescript dependency version is 4.7+
Node version: 16.15.0 OS: Windows
Code to reproduce: package.json
{
"name": "swagger-typescript-api-bug",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"fetch-types": "swagger-typescript-api -p https://my-website-api.com"
},
"license": "ISC",
"dependencies": {
"swagger-typescript-api": "^9.3.1"
}
}
tsconfig.json
{
"include": ["./src/**/*"],
"exclude": [],
"compilerOptions": {
"esModuleInterop": true,
"module": "ES6",
"moduleResolution": "NodeNext",
"target": "ES6"
},
"ts-node": {
"transpileOnly": true
}
}
running the fetch-types
script raises the following stack:
TypeError: host.fileExists is not a function
at getPackageJsonInfo (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:43798:37)
at Object.getPackageScopeForPath (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:43765:23)
at lookupFromPackageJson (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:116488:28)
at Object.getImpliedNodeFormatForFile (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:116482:200)
at acquireOrUpdateDocument (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:136051:47)
at Object.acquireDocumentWithKey (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:136026:20)
at getOrCreateSourceFileByPath (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:165211:41)
at Object.getOrCreateSourceFile [as getSourceFile] (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:165158:24)
at findSourceFileWorker (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:118298:29)
at findSourceFile (D:\Projects\WebstormProjects\testing-tools\node_modules\typescript\lib\typescript.js:118196:26)
error Command failed with exit code 1.
No error is raised if the dependency is Typescript 4.6.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 21
- Comments: 34 (4 by maintainers)
Commits related to this issue
- gh-3043 Speculative fix to stroom-ui build Fixing typescript dep ver at 4.7.4 due to this https://github.com/acacode/swagger-typescript-api/issues/370 — committed to gchq/stroom by at055612 2 years ago
- gh-3043 Speculative fix to stroom-ui build Fixing typescript dep ver at 4.7.4 due to this https://github.com/acacode/swagger-typescript-api/issues/370 (cherry picked from commit eb95156366585bb63163... — committed to gchq/stroom by at055612 2 years ago
- Freeze swagger-typescript-api and typescript versions swagger-typescript-api has a fatal bug at either typescript@4.7.X or swagger-typescript-api@10.X (See https://github.com/acacode/swagger-typescri... — committed to emonadeo/GDOL by emonadeo 2 years ago
- fix: swagger-typescript-api compile error https://github.com/acacode/swagger-typescript-api/issues/370 — committed to RootLinkFE/rh.js by giscafer 2 years ago
- chore: fix https://github.com/acacode/swagger-typescript-api/issues/370 — committed to ng-alain/delon by cipchk 2 years ago
If you use yarn you can workaround this issue by using yarn resolutions in your
package.json
.swagger-typescript-api@^10.0.1
has a dependency oftypescript@^4.7.4
which resolves totypescript@4.8.2
for me, which causes this error.Adding a resolution of
"typescript": "4.7.4"
ensures the breaking version of TypeScript isn’t used.This solution, which only overrides swagger-typescript-api, works for me using npm:
@Misinin make sure to be using npm@8.3 or higher: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
Helps with yarn
Same issue, after a lot of testing it seems that swagger-typescript-api simply does not work with typescript 4.8.2 (released 16 hours ago). When locking typescript to
4.7.4
(using e.g. yarn resolutions) it works.Since swagger-typescript-api requests
"typescript: "^4.7.4"
it will automatically pick up typescript 4.8.2, so unless you got an existing lockfile that resolves typescript ^4.7.4 to 4.7.4 (the no longer latest version) swagger-typescript-api won’t run.@js2me Any progress? Can you solve it first, my test failed:
👍 Or Typescript 4.6.2 if using moduleResolution = Node16 or NodeNext
Indeed, thanks for the heads-up 😃
same error
@vanslly Thank you so much that helped me!
I couldn’t get the resolution stuff to work in yarn berry, so used @jnig’s PR linked above until merged
src/formatFileContent.js
class LanguageServiceHost { … fileExists(file) { return ts.sys.fileExists(file); } …
Thank you for adding the above.
This worked for me. Thanks @matsgm!
We’re having the same problem. Thanks to @treet who explained this very well -
This means that people interacting with this generator via
npx
like so:Are not going to be able to escape the error by going back to an earlier version of this library
Because, both
9.3.1
and the latest release10.0.1
pull in typescript4.8.2
due to the typescript package.json dependency using the minor version bump requirement^4.x
in both versions.So even though it was recently bumped from 4.2.4 to 4.7.4 in the latest 10.0 release, both will still pull in 4.8.2.
It seems that this library swapped to using typescript
^4.x
as far back as the 2.0 releaseActually sorry got it working thanks everyone for help
Having the same issue. @vanslly’s solution fixes the issue for me. Thanks!