[Web]Fix: expo-modules-core server side error
Why
Hey, @tsapeta. I noticed that the expo-modules-core recently underwent some changes and is now broken on Next.js.
The reason for this issue is that we are importing SharedObject and NativeModule globally on the server side. Therefore, I have come up with a simple solution to fix the export of NativeModule and SharedObject.
But I'm not a big fan of this change because since we have already exported these global variables in './web/index', it feels like these NativeModule and SharedObject are being duplicated on web, which is a bit unnecessary.
How
Add a precondition for NativeModule and SharedObject: if they are in a server-side environment, simply export an empty object.
Test Plan
I have tested our project and created a minimal reproducible example locally. If you want, I can show you this example. However, I don't think it's necessary because this change doesn't break anything.
Checklist
- [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md).
- [x] Conforms with the Documentation Writing Style Guide
- [ ] This diff will work correctly for
npx expo prebuild& EAS Build (eg: updated a module plugin).
Let me know if anything else needs to be updated or if you have any feedback!
Hey @tsapeta, yeah, that makes sense. So now the problem is clear: The issue lies in the import statement in /web/index.web.ts not working because it actually requires all variables to be exported from CoreModule.ts.
I have just updated my code and tested my example, and it is fixed. Could you please check it again when you have some free time?
thank you! 🫡