代码之家  ›  专栏  ›  技术社区  ›  MyNameIsGuzse

NPM包有依赖项错误,即使在我手动安装它们之后

  •  -2
  • MyNameIsGuzse  · 技术社区  · 6 年前

    我想用这个 Imgur package 从我的角网应用程序的NPM。安装之后,一切都很好。即使在导入之后。但是,一旦使用包初始化了一个变量,我就会得到编译错误,声称代码中存在解决错误的方法,例如“crypto”。 NPM版本:5.6.0 角度版本:6.2.9

    知道是什么引起了这个问题吗?你知道怎么修吗?

    我尝试安装看似丢失的包,但当我再次尝试编译时,它们仍然被视为丢失。 我还尝试将我的节点版本降级为旧版本,但没有效果。 也没有删除我的节点模块并重新安装它们。

    下面是我在typescript中用来初始化模块的代码:

    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 回复  |  直到 6 年前
        1
  •  0
  •   Quentin    6 年前

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

    这个 imgur 模块不是为在Web浏览器中运行而设计的,因此它不适用于Angular。它依赖于许多node.js特定的API(如文件写入)。

        2
  •  0
  •   Manu    6 年前

    您的安装似乎已损坏。最好的方法是手动删除 node_modules 文件夹并再次运行NPM安装。这应该在新安装后工作。

        3
  •  0
  •   skdonthi    6 年前

    请删除 node_modules 并运行 npm install 再一次。。。

    此外 IMGUR ,您也必须安装它的类型。

    npm install @types/imgur