Search code examples
node.jsimportrequirebcryptnestjs

Keyword import returns undefiend for bcrypt package


I'm writing on basic Nestjs starter project and when I import bcrypt - it returns undefined, but when I use require('bcrypt') it returns the bcrypt object.

How to import bcrypt via the import keyword?


My os is MacOS and I've installed bcrypt package v ^3.0.0. My node version is 10.14.1;


Solution

  • Import the anonymous function and give it a name

    import * as bcrypt from 'bcrypt'
    

    Alternatively, install the typings for bcrypt.

    npm install --save-dev @types/bcrypt
    

    Then import and use the functions directly

    import {hash} from 'bcrypt';