【发布时间】:2017-05-03 21:49:13
【问题描述】:
我有一个 angular2 应用程序,它使用 angular-cli 执行脚手架和其他任务,但现在我不能在我的 angular2 应用程序上使用 jsonwebtoken。
我已经添加了依赖
yarn add --save jsonwebtoken
我实际上可以在node_modules 看到图书馆,我这样做了
import { jwt } from 'jsonwebtoken'
在我的 TypeScript 代码中,IDE 没有给我任何警告,因此它可以正确找到依赖项。
但是当我执行npm start 或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没有回答。
-
react-validation-mixin、isemail 和 joi 中的一些相关错误将我带到了这个one,当它们描述了在导入依赖于
dns、net或其他一些本机模块的库时出现类似问题时来自节点,让我认为在使用webpack专门使用这种库时存在一些问题(我没有专业知识来确定这一点,如果我错了,请更正),解决方法是添加以下行到webpack.confignode: { net: 'empty', tls: 'empty', dns: 'empty' }
但我的问题是,使用 angular-cli 有 no way to override webpack config 并且无意更改它。
所以我不知道在这里做什么,你知道如何在我的 angular-cli 应用程序中使用 jsonwebtoken 吗?
【问题讨论】:
标签: angular webpack angular-cli json-web-token