Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: navigator is not defined when using nestjs #1165

Closed
eassa opened this issue Nov 30, 2023 · 4 comments
Closed

ReferenceError: navigator is not defined when using nestjs #1165

eassa opened this issue Nov 30, 2023 · 4 comments
Labels
bug client related to peerjs client released

Comments

@eassa
Copy link

eassa commented Nov 30, 2023

hey,
i am using nestjs to create a nodejs service as a client to publish streaming from one computer to another connected in the web.
after installing peerjs and initiate it like this
this.peer = new PeerJs();
it fails with this error

C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:8
        readonly isIOS = ["iPad", "iPhone", "iPod"].includes(navigator.platform);
                                                      ^
ReferenceError: navigator is not defined
    at new <anonymous> (C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:8:55)
    at Object.<anonymous> (C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:7:25)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Repose\webrtc\spring\src\app.service.ts:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
@dingavinga1
Copy link

hey,
i am using nestjs to create a nodejs service as a client to publish streaming from one computer to another connected in the web.
after installing peerjs and initiate it like this
this.peer = new PeerJs();
it fails with this error

C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:8
readonly isIOS = ["iPad", "iPhone", "iPod"].includes(navigator.platform);
^
ReferenceError: navigator is not defined
at new (C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:8:55)
at Object. (C:\Repose\webrtc\spring\node_modules\peerjs\dist\lib\supports.ts:7:25)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object. (C:\Repose\webrtc\spring\src\app.service.ts:3:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

I might be wrong but I think navigator is specific to browsers i.e. the frontend, while NestJS is a full-stack framework. Could you provide more information like where in your NestJS server you are trying to access navigator?

@CemalYagcioglu
Copy link

Same issue is discussed here:
#819

@thePeeyush
Copy link
Contributor

Go to node modules/peerjs/dist/bundler.mjs

line 104

change the code from 104 to 108 with the code given below:

this.isIOS = typeof navigator !== "undefined" ? [
            "iPad",
            "iPhone",
            "iPod"
        ].includes(navigator.platform) : false;

Note - this fix works in local build only.

@irgalamarr irgalamarr added client related to peerjs client has PR issue has an associated pull request labels Feb 24, 2024
@irgalamarr irgalamarr removed the has PR issue has an associated pull request label Mar 9, 2024
@irgalamarr irgalamarr added the bug label Mar 9, 2024 — with Linear
github-actions bot pushed a commit that referenced this issue May 11, 2024
## [1.5.3](v1.5.2...v1.5.3) (2024-05-11)

### Bug Fixes

* navigator is not defined. ([#1202](#1202)) ([4b7a74d](4b7a74d)), closes [#1165](#1165)
* remove need for `unsafe-eval` ([3fb31b3](3fb31b3))
Copy link

🎉 This issue has been resolved in version 1.5.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug client related to peerjs client released
Projects
None yet
Development

No branches or pull requests

5 participants