简体   繁体   English

TypeScript 未访问或导入节点模块

[英]TypeScript not accessing or importing node module

first, to say, I am new to Angular.首先,要说的是,我是 Angular 的新手。

I am trying to use the crypto-js module to encrypt and decrypt a string passed to a Service.我正在尝试使用 crypto-js 模块来加密和解密传递给服务的字符串。 The service is injected to whoever uses it.该服务被注入到使用它的任何人。 My Problem is, apparently I can not Import a reference to this module.我的问题是,显然我无法导入对此模块的引用。

My current set up is:我目前的设置是:

Angular CLI: 6.0.8
Node: 9.7.1
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.3.2
typescript                        2.7.2
webpack                           4.8.3

The crypto-js package was installed by npm and the folder is properly located in the node_modules folder as you can see in the screenshot. crypto-js 包由 npm 安装,该文件夹正确位于 node_modules 文件夹中,如屏幕截图所示。

文件夹位于 node_modules

My Service (It will not contain any sensitive information in the code in future, just for testing) looks like this:我的服务(以后不会在代码中包含任何敏感信息,仅供测试)如下所示:

import {Injectable, OnDestroy} from "@angular/core";
// will be used in future
import { CookieService } from "ngx-cookie-service";

const algorithm = 'aes-256-ctr';
// Todo generate password
const password = '1xap0957/ara=Xv9';

@Injectable()
export class Abc_tService implements OnDestroy {

  Enc(text) {
    // Encrypt
    var en = this.encrypt(text);
    console.log(en);
    console.log(this.decrypt(en));
  }

  private encrypt(text: string): string {

    return text;
  }

  private decrypt(text): string {

    return text;
  }

  ngOnDestroy() {

  }
}

The Enc(text) Method is used for testing. Enc(text) 方法用于测试。 Now my problem is, that I can't import or access the crypto-js module.现在我的问题是,我无法导入或访问 crypto-js 模块。

悬停显示 IDE 还没有访问权限

When I try to import it, I also can't access it.当我尝试导入它时,我也无法访问它。 Now my imported reference seems to reference my own class:现在我导入的引用似乎引用了我自己的类:

引用自己的类

My Goal is to use the crypto-js module in my service.我的目标是在我的服务中使用 crypto-js 模块。 What am I missing?我错过了什么?

Thanks to Aluan Haddads comment on my question.感谢 Aluan Haddads 对我的问题发表评论。 The Solution simply was, I had to install the type.解决方案很简单,我必须安装该类型。 I did this using npm with the command:我使用 npm 和命令执行此操作:

npm install --save @types/crypto-js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM