fusionauth-typescript-client icon indicating copy to clipboard operation
fusionauth-typescript-client copied to clipboard

Issues with building app with fusionauth-typescript-client

Open Ilchuk-Mihail opened this issue 4 years ago • 6 comments

When I try to build app tsc --build with lib installed, I get an error like this:

node_modules/@fusionauth/typescript-client/build/src/IRESTClient.d.ts:3:46 - error TS7016: Could not find a declaration file for module 'node-fetch'. '/Users/.../node_modules/@fusionauth/typescript-client/node_modules/node-fetch/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/node-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-fetch';`

import { RequestCredentials, Response } from "node-fetch";

node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.d.ts:3:36 - error TS7016: Could not find a declaration file for module 'node-fetch'. '/Users/.../node_modules/@fusionauth/typescript-client/node_modules/node-fetch/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/node-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-fetch';`

import { RequestCredentials } from "node-fetch";
             

Typescript and lib versions:

  • typescript 4.3.5
  • @fusionauth/typescript-client: 1.30.0

The quick fix is to add "@types/node-fetch": "^2.5.7" to dependencies.

Current version of node-fetch already contains types but, there is no such type like RequestCredentials.

Is there any other fix ? or is it possible to update node-fetch here to the latest one ?

Ilchuk-Mihail avatar Sep 16 '21 16:09 Ilchuk-Mihail

Thanks for the bug report. Will take a look in the next few days.

mooreds avatar Sep 21 '21 22:09 mooreds

Same issue with 1.30.2.

koshkarov avatar Nov 09 '21 14:11 koshkarov

for anyone else coming here from a google search, here's how i got it "working" in my project:

install node package patch-package npm install --save patch-package

in your package.json file add the following script to the "scripts" block "postinstall": "patch-package"

in /node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.d.ts: add //@ts-ignore right above import { RequestCredentials } from "node-fetch";

repeat in /node_modules/@fusionauth/typescript-client/build/src/IRESTClient.d.ts for import { RequestCredentials, Response } from "node-fetch";

after saving your changes, in your project root run npx patch-package @fusionauth/typescript-client

and voila.

this is really more of a band-aid rather than a proper fix but if you need to go live asap this seems to work.

ocean-rey avatar Nov 17 '21 15:11 ocean-rey

@ocean-rey You could also try adding "@types/node-fetch": "^2.5.7" to your dev/dependencies.

Ilchuk-Mihail avatar Nov 17 '21 15:11 Ilchuk-Mihail

@ocean-rey You could also try adding "@types/node-fetch": "^2.5.7" to your dev/dependencies.

I did try this but it didn't seem to work for me; perhaps i'm doing something wrong?

ocean-rey avatar Nov 17 '21 15:11 ocean-rey

For me tsc --build didn't work (errors at the first comment), but when I installed that package to devDependencies, the build works. (So just adding this and reinstall packages works for me)

Ilchuk-Mihail avatar Nov 17 '21 15:11 Ilchuk-Mihail