我有一个 angular2 应用程序,它使用角度-cli https://github.com/angular/angular-cli%20angular-cli用于脚手架和其他任务,但现在我不能使用jsonwebtoken https://github.com/auth0/node-jsonwebtoken%20jsonwebtoken在我的 angular2 应用程序上。
我已经添加了依赖
yarn add --save jsonwebtoken
我实际上可以看到图书馆node_modules
,我做
import { jwt } from 'jsonwebtoken'
在我的 TypeScript 代码中,IDE 没有给我任何警告,因此它可以正确找到依赖项。
但当我这样做时npm start
or yarn start
我有以下错误消息
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"'.
当我在互联网上搜索错误时,我跟踪了一系列对话和相关项目。
我发现:
有类似的问题,但不是这样detailed https://stackoverflow.com/questions/40916851/angular-2-can-not-find-module-jsonwebtoken但它还没有回答。
-
一些相关错误反应验证混合 https://github.com/jurassix/react-validation-mixin/issues/17, isemail https://github.com/hapijs/isemail/issues/26 and joi https://github.com/hapijs/joi/issues/748#issuecomment-235000400引导我到这个one https://github.com/hapijs/joi/issues/665,当他们描述依赖于导入库的类似问题时dns
, net
或来自节点的其他一些本机模块,让我认为仅使用此类库时存在一些问题webpack
(我没有专业知识来确定这一点,如果我错了,请纠正),解决方法是将以下行添加到webpack.config
node: {
net: 'empty',
tls: 'empty',
dns: 'empty'
}
但我的问题是,对于 Angular-cli 有无法覆盖 webpack 配置 https://github.com/angular/angular-cli/issues/1656#issuecomment-239366723并且无意改变这一点。
所以我不知道在这里做什么,你知道如何在我的 angular-cli 应用程序中使用 jsonwebtoken 吗?