swagger-typescript-api
swagger-typescript-api copied to clipboard
swagger-typescript-api does not work with TypeScript >=4.8.0
The issue I've had
I've recently ran into issues getting swagger-typescript-api to work in my project even though it worked a few months ago.
The issue that I've ran into kept throwing me an exception:
TypeError: host.fileExists is not a function
at Object.fileExists (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:167586:63)
at Object.host.fileExists (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:117448:47)
at getPackageJsonInfo (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44458:37)
at loadModuleFromSpecificNodeModulesDirectory (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:45000:27)
at loadModuleFromImmediateNodeModulesDirectory (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44981:58)
at C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44971:39
at Object.forEachAncestorDirectory (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:8370:26)
at loadModuleFromNearestNodeModulesDirectoryWorker (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44965:19)
at loadModuleFromNearestNodeModulesDirectory (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44957:16)
at tryResolve (C:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f\node_modules\typescript\lib\typescript.js:44052:34)
Findings
After digging for a few hours I've managed to trace that it was caused by a later version of TypeScript. It stops working if version >=4.8.0 is used.
This issue is not reproduced by cloning the repository and doing an npm i due to the package-lock.json file explicitly stating, that typescript 4.7.4 should be used. However package-lock.json is not included as part of an npm package. This and the fact, that the typescript dependency is with a caret (^) symbol installs the latest version of typescript for new projects depending on this package.
Reproduction
To reproduce this error you can simply:
git clone https://github.com/acacode/swagger-typescript-api.gitnpm i [email protected]npm i
This will yield an error during the tests run.
How to fix it on my machine?
If you're just a passer-by like me who stumbled across this issue on their project - you can resolve it like this:
If the package is in your package.json
npm i [email protected]
Please keep in mind that this will affect your whole project.
If you're using npx
- Find
npxcache forswagger-typescript-apimine was inC:\Users\<MyUsername>\AppData\Local\npm-cache\_npx\ad2f6472e51cc62f - Add
"typescript": "4.7.4"to thepackage.json npm i
Duplicate of #370
Hi @martis347 , I think this problem fixed in 11.* release. Because of this I'm closing this issue, please reopen if you are still occurring with this bug