即使手动安装npm软件包也有依赖关系错误

时间:2019-01-19 16:45:13

标签: javascript node.js angular typescript npm

我正在尝试在Angular Web应用程序中使用NPM的Imgur package。安装后,一切似乎都很好。即使在导入之后。但是,一旦使用程序包初始化了变量,我就会得到编译错误,声称我的代码中存在解析错误,例如'crypto'。 NPM版本:5.6.0 角度版本:6.2.9

关于导致此问题的原因的任何想法?关于如何解决它的任何想法?

我尝试安装看似缺失的软件包,但是当我再次尝试编译时,它们仍然被视为缺失。 我也尝试将节点版本降级到较旧版本,但无济于事。 删除我的node_modules并重新安装它们都没有。

这是我用来在打字稿中初始化模块的代码:

import { Component, OnInit } from '@angular/core';
import * as Convert from 'color-convert';
import * as Hex from 'hex2dec';
import * as ClarifaiSVC from '../clarifai_service/clarifai.service';
import * as Imgur from 'imgur';

@Component({
    selector: 'app-imagery',
    templateUrl: './imagery.component.html',
    styleUrls: ['./imagery.component.css']
})

export class ImageryComponent implements OnInit {

    constructor(private Clarifai: ClarifaiSVC.ClarifaiService, private Imgur: Imgur) { }
}

这是服务后在npm日志中的内容:

ERROR in ./node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\aws-sign2'ERROR in ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\aws4'
ERROR in ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\ecc-jsbn'
ERROR in ./node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\http-signature\lib'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\http-signature\lib'
ERROR in ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\oauth-sign'
ERROR in ./node_modules/request/lib/oauth.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request\lib'
ERROR in ./node_modules/request/lib/helpers.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request\lib'
ERROR in ./node_modules/request/lib/hawk.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request\lib'
ERROR in ./node_modules/sshpk/lib/identity.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\sshpk\lib'ERROR in ./node_modules/sshpk/lib/utils.js
ERROR in ./node_modules/sshpk/lib/formats/openssh-cert.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\sshpk\lib\formats'
ERROR in ./node_modules/sshpk/lib/formats/ssh-private.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\sshpk\lib\formats'
ERROR in ./node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\fs.realpath'
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request\lib'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\forever-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request'
--------------------------------------------


--------------------------------------------
This just goes on for a while
--------------------------------------------


--------------------------------------------
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\request'
ERROR in ./node_modules/sshpk/lib/ed-compat.js
Module not found: Error: Can't resolve 'stream' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard\node_modules\sshpk\lib'ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\Gilian\Documents\School\3EA2_18-19\Internet Of Things\src\dashboard\dashboard

3 个答案:

答案 0 :(得分:0)

您的安装似乎已损坏。最好的方法是手动删除node_modules文件夹,然后重新运行npm install。这应该在全新安装后起作用。

答案 1 :(得分:0)

请删除node_modules,然后再次运行npm install ...

除了 imgur ,您还必须安装其类型。

npm install @types/imgur

答案 2 :(得分:0)

Crypto is a built-in Node.js module。它不是普通的JavaScript。

imgur模块并非旨在在Web浏览器中运行,因此它不适用于Angular。它依赖于许多特定于Node.js的API(例如文件编写)。