gpt4 book ai didi

jwt - 找不到模块 : Error: Can't resolve 'crypto' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jwa'

转载 作者:行者123 更新时间:2023-12-02 02:56:47 28 4
gpt4 key购买 nike

我将在我的 Angular6 项目中安装 jsonwebtoken 模块npm i jsonwebtoken。安装了 jsonwebtoken 模块依赖项 jwa,但该 index.js 文件 crypto require 错误无法解析“crypto”,但我已经安装了 crypto 模块。

请帮助解决问题。

我的错误:

ERROR in ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jwa'
ERROR in ./node_modules/jws/lib/sign-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'
ERROR in ./node_modules/jws/lib/verify-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'
ERROR in ./node_modules/jws/lib/data-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'

最佳答案

我遇到了和你一样的问题,我也解决了。您可以按照以下步骤操作:

  1. 将此文件添加到根目录

patch.js

const fs = require('fs');
const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';

fs.readFile(f, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}');

fs.writeFile(f, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
  • 将此命令添加到package.json文件
  • package.json

    {...
    "scripts": {
    "postinstall": "node patch.js",
    ...
    }
    }

    引用:https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d

    关于jwt - 找不到模块 : Error: Can't resolve 'crypto' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jwa' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530289/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com