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

crash at expo metro build #15

Closed
ericlyoung opened this issue Mar 18, 2024 · 6 comments
Closed

crash at expo metro build #15

ericlyoung opened this issue Mar 18, 2024 · 6 comments
Labels
duplicate This issue or pull request already exists

Comments

@ericlyoung
Copy link

running: npx expo export -p web
as described on https://docs.expo.dev/distribution/publishing-websites/

╰─>$ npx expo export -p web
Static rendering is enabled. Learn more
Starting Metro Bundler
λ Bundled 6747ms (node_modules/expo-router/node/render.js)
Web Bundled 6871ms (node_modules/expo-router/entry.js)

Metro error: window is not defined

1 | import RTCView from './RTCView';
2 |

3 | window.MediaStream.prototype.release = function release() {
| ^
4 | this.getTracks().forEach((track) => track.stop());
5 | };
6 |

Call Stack
factory (node_modules/react-native-webrtc-web-shim/src/react-native-webrtc-web-shim.web.js:3)
loadModuleImplementation (node_modules/metro-runtime/src/polyfills/require.js:342:5)
guardedLoadModule (node_modules/metro-runtime/src/polyfills/require.js:240:12)
r (node_modules/metro-runtime/src/polyfills/require.js:127:7)
factory (node_modules/react-native-webrtc-web-shim/index.js:1)
loadModuleImplementation (node_modules/metro-runtime/src/polyfills/require.js:342:5)
guardedLoadModule (node_modules/metro-runtime/src/polyfills/require.js:240:12)
r (node_modules/metro-runtime/src/polyfills/require.js:127:7)
factory (app/calls/[id].js:8)
h (node_modules/metro-runtime/src/polyfills/require.js:342:5)

@8BallBomBom
Copy link
Member

Similar issue to #14
Will be resolved in the next major update 👍🏻

@8BallBomBom 8BallBomBom added the duplicate This issue or pull request already exists label Mar 19, 2024
@ericlyoung
Copy link
Author

Similar issue to #14 Will be resolved in the next major update 👍🏻

Got any quick hint at how to hack around this for now?

@hungrymike
Copy link

Similar issue to #14 Will be resolved in the next major update 👍🏻

Got any quick hint at how to hack around this for now?

If you're using the new expo router did you try to disable SRR? On app.json switch web output to single.

@gavrilikhin-d
Copy link

gavrilikhin-d commented Jun 24, 2024

@8BallBomBom sorry, when this major update is roughly expected?

@gavrilikhin-d
Copy link

Similar issue to #14 Will be resolved in the next major update 👍🏻

Got any quick hint at how to hack around this for now?

Here is the patch we use:

diff --git a/node_modules/react-native-webrtc-web-shim/src/react-native-webrtc-web-shim.web.js b/node_modules/react-native-webrtc-web-shim/src/react-native-webrtc-web-shim.web.js
index 7d10049..5b823e6 100644
--- a/node_modules/react-native-webrtc-web-shim/src/react-native-webrtc-web-shim.web.js
+++ b/node_modules/react-native-webrtc-web-shim/src/react-native-webrtc-web-shim.web.js
@@ -1,5 +1,7 @@
 import RTCView from './RTCView';
 
+if (typeof window !== "undefined") {
+
 window.MediaStream.prototype.release = function release() {
   this.getTracks().forEach((track) => track.stop());
 };
@@ -8,6 +10,8 @@ window.MediaStreamTrack.prototype._switchCamera = function _switchCamera() {
   console.warn('_switchCamera is not implemented on web.');
 };
 
+}
+
 const {
   RTCPeerConnection,
   RTCIceCandidate,
@@ -18,13 +22,15 @@ const {
   RTCErrorEvent,
   MediaStream,
   MediaStreamTrack,
-} = window;
+} = typeof window !== "undefined" ? window : {};
 
-const { mediaDevices, permissions } = navigator;
+const { mediaDevices, permissions } = typeof window !== "undefined" ? navigator : {};
 
 function registerGlobals() {
-  window.mediaDevices = navigator.mediaDevices;
-  window.permissions = navigator.permissions;
+  if (typeof window !== "undefined") {
+    window.mediaDevices = navigator.mediaDevices;
+    window.permissions = navigator.permissions;
+  }
 }
 
 export {

@8BallBomBom
Copy link
Member

8BallBomBom commented Jun 24, 2024

Currently focused on the New Arch update for the main repo.
Hoping to address all outstanding issues on this repo shortly after.

Will need to look into this before deciding the best course of action 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants