【问题标题】:Module not found: Can't resolve imported dependency "crypto" when using jsonwebtoken package找不到模块:使用 jsonwebtoken 包时无法解析导入的依赖项“crypto”
【发布时间】:2021-12-30 17:49:44
【问题描述】:

我正在使用 quasar cli 创建一个 vue 3 应用程序。我已经通过纱线安装了 jsonwebtoken。当我尝试编译应用程序时,出现以下错误:

App •  ERROR  •  UI  in ./node_modules/jwa/index.js

Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: yarn add crypto

 App •  ERROR  •  UI  in ./node_modules/jwa/index.js

Module not found: Can't resolve imported dependency "util"
Did you forget to install it? You can run: yarn add util

 App •  ERROR  •  UI  in ./node_modules/jws/lib/data-stream.js

Module not found: Can't resolve imported dependency "stream"
Did you forget to install it? You can run: yarn add stream

 App •  ERROR  •  UI  in ./node_modules/jws/lib/data-stream.js

Module not found: Can't resolve imported dependency "util"
Did you forget to install it? You can run: yarn add util

我可以运行“yarn add util”和“yarn add stream”,这些错误就会消失,但我不知道这是否是问题的正确解决方案。无论如何,我不能只运行“yarn add crypto”来解决该错误。当你这样做时,你会收到以下警告......

warning crypto@1.0.1: This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.

但我不确定这里需要做什么才能“切换到内置的”,并且很好奇是否每个人在使用 jsonwebtoken 时都会遇到这种情况?

【问题讨论】:

    标签: node.js vue.js jwt quasar


    【解决方案1】:

    我一直无法弄清楚如何解决我在尝试使用 jsonwebtoken 时遇到的问题。我还尝试了其他几个 JWT 包,但也没有成功。最后我遇到了 jwt-decode ,因为我需要在客户端上做的唯一一件事就是解码我尝试过的令牌,它工作得很好并且非常易于使用:

    https://www.npmjs.com/package/jwt-decode

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 2021-05-04
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 2020-11-15
      相关资源
      最近更新 更多