Невозможно прочитать свойство 'prototype' из неопределенного в угловом - PullRequest
0 голосов
/ 27 мая 2019

я установил пакет через npm в angular (последняя версия), который использует некоторые библиотеки типа "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)

Понятия не имею Что мне делать!

спасибо за любую помощь!

для получения дополнительной информации:

пакет проверен в реакции и нормально работал

URL пакета: 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);
  }
}

1 Ответ

1 голос
/ 27 мая 2019

Эта библиотека зависит от пакета fs, который является пакетом node.js для создания / чтения / изменения файлов в вашей файловой системе.Поскольку вы не можете сделать это в браузере, вам никогда не понадобятся эти пакеты.Вы можете удалить их.

Согласно странице github, есть клиентская часть ПОДЧАТЬ , вы должны включить это вместо:

import { Component, OnInit  } from '@angular/core';
import * as Chat from 'podchat/src/chat-browser';

Я неуверен в правильности синтаксиса для импорта, но я надеюсь, что вы поняли идею.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...