Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

like image 657
Link Avatar asked Dec 08 '18 16:12

Link


1 Answers

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';
like image 170
Kim Kern Avatar answered Oct 13 '22 15:10

Kim Kern