我通过npm(最新版本)通过npm安装了一个软件包,该软件包使用了一些库,例如“ fs,stream,..”。
当我运行ng serve
时,它会显示许多错误,例如:
Can't resolve 'crypto' in '\node_modules\..'
Can't resolve 'fs' in '\node_modules\..'
Can't resolve 'stream' in '\node_modules\..'
为解决错误,我将此代码添加到了pckage.json:
"browser": {
"fs": false,
"path": false,
"os": false,
"crypto" : false,
"stream" : false,
"http" : false,
"tls" : false,
"zlib" : false,
"https" : false,
"net" : false
}
之后,我看到了这两个错误:
global is not defined
process is not defined
要解决这两个问题,我将这部分代码添加到我的polyfills.ts
中:
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};
错误消失了,但是现在我在控制台中遇到了这个错误:
TypeError: Cannot read property 'prototype' of undefined
at Object.inherits (inherits_browser.js:5)
at Object../node_modules/sshpk/lib/ed-compat.js (ed-compat.js:25)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/sshpk/lib/private-key.js (private-key.js:17)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/sshpk/lib/fingerprint.js (fingerprint.js:11)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/sshpk/lib/key.js (key.js:8)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/sshpk/lib/index.js (index.js:3)
我不知道该怎么办!
感谢您的帮助!
有关更多信息:
经过测试的包装可以正常工作
程序包网址:https://www.npmjs.com/package/podchat
和角组件
import { Component, OnInit } from '@angular/core';
import * as Chat from 'podchat';
@Component({
selector: 'app-c2',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
flag: boolean;
params = {
socketAddress: "wss://chat-sandbox.pod.land/ws", // {**REQUIRED**} Socket Address
ssoHost: "https://accounts.pod.land", // {**REQUIRED**} Socket Address
platformHost: "https://sandbox.pod.land:8043/srv/basic-platform", // {**REQUIRED**} Platform Core Address
fileServer: "https://sandbox.pod.land:8443", // {**REQUIRED**} File Server Address
serverName: "chat-server", // {**REQUIRED**} Server to to register on
grantDeviceIdFromSSO: false,
enableCache: true, // Enable Client side caching
token: "80fdb34b3086438e91061d0902f33c7b", // {**REQUIRED**} SSO Token
wsConnectionWaitTime: 500, // Time out to wait for socket to get ready after open
connectionRetryInterval: 5000, // Time interval to retry registering device or registering server
connectionCheckTimeout: 10000, // Socket connection live time on server
messageTtl: 86400000, // Message time to live
reconnectOnClose: true, // auto connect to socket after socket close
asyncLogging: {
onFunction: true, // log main actions on console
onMessageReceive: true, // log received messages on console
onMessageSend: true, // log sent messaged on console
actualTiming: true // log actual functions running time
}
};
constructor() {
}
ngOnInit() {
const chat = new Chat(this.params);
}
}
答案 0 :(得分:1)
该库取决于fs
软件包,该软件包是一个node.js软件包,用于在文件系统中创建/读取/修改文件。由于您无法在浏览器中执行此操作,因此不再需要这些软件包。您可以删除它们。
根据github页面,有podchat的客户端部分,您应该改为包含它:
import { Component, OnInit } from '@angular/core';
import * as Chat from 'podchat/src/chat-browser';
我不确定要导入的语法正确,但是希望您能理解。