반응형
Angular 6 - browser-crypto.js:3 Uncaught ReferenceError: global이 정의되지 않았습니다.
나는 socketjs를 구현하고 있습니다.하지만 아래 오류가 발생했습니다.
아래는 제가 사용하고 있는 소켓과 스탬핑 패키지입니다.
import * as SockJS from 'sockjs-client';
import * as Stomp from 'stompjs/lib/stomp.js';
잘 부탁드립니다.
여기 내 각도 코드가...
import * as Socket from 'socket.io-client';
import * as Stomp from 'stompjs/lib/stomp.js';
initializeWebSocketConnection2(){
let ws = new Socket(this.serverUrl);
this.stompClient = Stomp.over(ws);
let that = this;
this.stompClient.connect({}, function(frame) {
that.stompClient.subscribe("/test", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
that.stompClient.subscribe("/operation", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
});
}
이것을 폴리필즈에 추가합니다.
(window as any).global = window
먼저 입력하는 소켓 클라이언트를 설치해야 합니다.
npm install --save @types/socket.io
그런 다음 다음 다음과 같이 구성 요소 또는 서비스에서 socket.io -client를 가져올 수 있습니다.
import * as Socket from 'socket.io-client';
코드를 이렇게 변경합니다.
let ws = Socket(this.serverUrl);
제 경우 index.html 머리에 다음 스니펫을 추가하면 문제가 해결되었습니다.
<script type="application/javascript">
var global = window;
</script>
https://github.com/stomp-js/ng2-stompjs/issues/70 참조
다음 코드를 추가하면 됩니다.
<script>
var global = window; // fix global is undefined in socketjs-client
</script>
언급URL : https://stackoverflow.com/questions/51380166/angular-6-browser-crypto-js3-uncaught-referenceerror-global-is-not-defined
반응형
'codememo' 카테고리의 다른 글
| xtable 사용 시 data.frame 행 이름 제거 (0) | 2023.07.07 |
|---|---|
| .mongo'가 내부 또는 외부 명령, 작동 가능한 프로그램 또는 배치 파일로 인식되지 않습니다. (0) | 2023.07.07 |
| SQL Developer가 테이블을 나타내는 연결 아래에 테이블이 표시되지 않습니다. (0) | 2023.07.02 |
| 하나의 디렉토리에 있는 모든 파일을 반복 (0) | 2023.07.02 |
| Vuex, vuejs - 선택 요소 옵션에서 예상대로 바인딩되지 않음 (0) | 2023.07.02 |