我在项目中安装了openpgp库,并运行使用Android模拟器的服务。然后,它引发以下错误:
“主”线程上发生未捕获的异常。
java.lang.RuntimeException:无法创建应用程序com.tns.NativeScriptApplication:com.tns.NativeScriptException:
调用模块函数时出错
调用模块函数时出错
调用模块函数时出错
调用模块函数时出错
错误:com.tns.NativeScriptException:无法找到模块:“流”,相对于:app / tns_modules /
在解决此问题的其他解决方案中,建议从package.json文件中删除对@ angular / platform-server的调用,但我的package.json没有。
这是我代码的相关部分:
import { Injectable } from '@angular/core';
//import * as openpgp from 'openpgp';
import * as openpgp from 'openpgp';
@Injectable()
export class RsaKeyService {
constructor() { }
generateKey () {
const name: string = this.hashGen(7);
const email: string = this.hashGen(7) + '@test.com';
const keyOptions = {
userIds: [{ name: name, email: email }],
passphrase: this.hashGen(10),
curve: 'ed25519',
compression: openpgp.enums.compression.zip
}
const user = {};
return new Promise((resolve) => {
openpgp.generateKey(keyOptions)
.then((key) => {
user['privateKey'] = key.privateKeyArmored;
user['publicKey'] = key.publicKeyArmored;
localStorage.setItem('RSAKey', JSON.stringify(user));
resolve(true);
});
})
}
async encrypt(stringToEncrypt: string, receiverPublicKey) {
const options: any = {
data: stringToEncrypt,
publicKeys: await openpgp.key.readArmored(receiverPublicKey).then((data) => {return data.keys})
};
return await openpgp.encrypt(options)
.then((cipherText) => {
return cipherText.data;
}).catch((error) => {
console.log('Error', error);
})
}
async decrypt(encryptedMessage: string, dataAccess) {
const privateKey = await openpgp.key.readArmored(dataAccess['privateKey']).then((data) => {return data.keys[0]});
privateKey.decrypt(dataAccess['passphrase']);
return openpgp.decrypt({
privateKeys: [privateKey],
message: await openpgp.message.readArmored(encryptedMessage)
}).then((decryptedData) => {
return decryptedData.data;
})
}
hashGen(length) {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
}
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
// Uncomment and add to NgModule imports if you need to use two-way binding
import { NativeScriptFormsModule } from "nativescript-angular/forms";
// Uncomment and add to NgModule imports if you need to use the HttpClient wrapper
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
import { LoginComponent } from "./modules/components/login/login.component";
import { UserServiceService } from "./core/services/UserService.service";
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { HttpErrorInterceptor } from "./core/interceptors/http.interseptor";
import { HomeComponent } from "./modules/components/home/home.component";
import { AuthGuardService } from "./core/guards/guards.services";
import { token } from "./core/authentication/token";
import { HttpService } from "./core/services/http.service";
import { HttpModule } from "@angular/http";
import { HttpHeadersInterceptor } from "./core/interceptors/http.header.interceptor";
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { RsaKeyService } from "./core/services/rsa.key.service";
@NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule,
NativeScriptFormsModule,
HttpClientModule,
HttpModule,
NativeScriptHttpModule
],
declarations: [
AppComponent,
LoginComponent,
HomeComponent,
],
providers: [
HttpService,
UserServiceService,
AuthGuardService,
RsaKeyService,
token,
{
provide: HTTP_INTERCEPTORS,
useClass: HttpErrorInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: HttpHeadersInterceptor,
multi: true
}
],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class AppModule { }
{
"nativescript": {
"id": "org.nativescript.CriptoZoneApp",
"tns-ios": {
"version": "5.2.0"
},
"tns-android": {
"version": "5.2.1"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/http": "~7.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"nativescript-angular": "~7.2.1",
"nativescript-localstorage": "^2.0.0",
"nativescript-theme-core": "~1.0.4",
"openpgp": "^4.4.10",
"reflect-metadata": "~0.1.12",
"rxjs": "~6.3.0",
"rxjs-compat": "^6.4.0",
"tns-core-modules": "~5.2.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "~7.2.0",
"@nativescript/schematics": "~0.5.0",
"@ngtools/webpack": "~7.2.0",
"nativescript-dev-typescript": "~0.8.0",
"nativescript-dev-webpack": "~0.20.0"
},
"gitHead": "f548ec926e75201ab1b7c4a3a7ceefe7a4db15af",
"readme": "NativeScript Application"
}
答案 0 :(得分:0)
该库似乎使用stream
模块,该模块仅在节点环境中可用。您只能使用仅由JavaScript api编写的NPM模块,否则它可能无法在{N}环境中使用。