문제
TypeError: Cannot read property 'emit' of undefined
PeerJs 사용도중 사용자가 소켓 연결 시도해서 노드로 넘어가서 해당 오류 발생
원인
밑의 한줄이 문제였음 어차피 여기서 사용자 -> 서버로 웹소켓 전달을 하는 과정이니깐
socket.emit('join-room', ROOM_ID, id)
해결
socket.io 버전 2.5.0으로 다운그레이드했음
npm install '모듈명' 버전
npm install socket.io 2.3.0
npm install '모듈명'@^ 버전
npm install socket.io@^2.3.0
위에 명령어는 밑에 참고하여서 가져왔음
참고
TypeError: Cannot read property 'emit' of undefined
The problem is that Whenever I try to fire "this.io.emit" event a TypeError occurs. It gives only while I write this statement "this.io.emit" inside "socket.on" block otherwise, if I write it outside
stackoverflow.com
npm 패키지 버전의 중요성(feat. socket.io와undefined )
소켓통신을 위해 코드를 작성 중, 분명 다른 사람의 코드는 잘 돌아가는데, 그것을 똑같이 적용한 내 코드에서는 소켓의 프로퍼티가 정의되지 않았다는 에러가 났다. TypeError: Cannot read property 'emi
velog.io