I have an angular2 application that uses the angular-cli for the scaffold and other tasks, but now I can't use jsonwebtoken
on my angular2 application.
I have added the dependency
yarn add --save jsonwebtoken
and I actually can see the library at node_modules
, I do the
import { jwt } from 'jsonwebtoken'
in my TypeScript code and the IDE gives me no warning about it, so it can find the dependency correctly.
But when I do npm start
or yarn start
I have the following error message
ERROR in ./~/isemail/lib/index.js
Module not found: Error: Can't resolve 'dns' in '/home/$MY_USER_NAME_PLACE_HOLDER/dir/to/my/app/node_modules/isemail/lib'
@ ./~/isemail/lib/index.js 5:12-26
@ ./~/joi/lib/string.js
@ ./~/joi/lib/index.js
@ ./~/jsonwebtoken/sign.js
@ ./~/jsonwebtoken/index.js
@ ./src/app/_auth/authentication.service.ts
@ ./src/app/app.component.ts
@ ./src/app/index.ts
@ ./src/main.ts
@ multi main
ERROR in [default] /home/$MY_USER_NAME_PLACE_HOLDER/dir/to/my/appsrc/app/_auth/authentication.service.ts:41:24
Property 'validate' does not exist on type 'typeof "/home/$MY_USER_NAME_PLACE_HOLDER/dir/to/my/app/node_modules/@types/jsonwebtoken/index"'.
I follow a serie of conversations and related projects when I searched for the error on internet. And I found that:
There is a similar problem but no so detailed and it has not answer.
Some related errors in react-validation-mixin, isemail and joi lead me to this one, when they describe similar problems doing import of libraries that depends on
dns
,net
or some other native modules from node and makes me think that there is some problems when using this kind of libraries exclusively withwebpack
(I have no the expertise to be sure of that, please correct if I am wrong) and the workaround is to add the following lines to thewebpack.config
node: { net: 'empty', tls: 'empty', dns: 'empty' }
But my problem here is, with angular-cli there is no way to override webpack config and there is no intention to change that.
So I don't know what to do here, have you any idea of how can I use jsonwebtoken with my angular-cli application ?