2

I'm trying to use bcryptjs package in my React project. I'm getting following error:

Could not find a declaration file for module 'bcryptjs'. ‘…/node_modules/bcryptjs/index.js' 
implicitly has an 'any' type.
Try `npm i --save-dev @types/bcryptjs` if it exists or add a new declaration (.d.ts)
file containing `declare module 'bcryptjs';`

Running npm i --save-dev @types/bcryptjs makes import error to go away but when I try to use variables from the package, they are not found.

NodeJS version is node v16.17.0 and TS is use as well.

How can I fix it? Thanks

rumon
  • 466
  • 2
  • 8
  • 21

2 Answers2

0

Try using below option:

npm i bcryptjs @types/bcryptjs

and then, add the below line

import { hash, compare } from 'bcryptjs';

Make sure that "allowSyntheticDefaultImports" is set to "true" in your tsconfig.json file

-1

Try running the command npm i --save-dev @types/bcryptjs or yarn add --dev @types/bcryptjs if you're using yarn to get the type definitions for this module.

TeeBeeGee
  • 89
  • 1
  • 3