doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.25k stars 1k forks source link

RNTP module not loading properly with NextJS / Solito #2301

Closed 9mzodiac closed 5 months ago

9mzodiac commented 5 months ago

I'm using Solito with NextJS and building a web app that imports react native track player. My next app is transpiling the RNTP package like it does for other react native packages but I'm getting an error when I run the app. Any help would be appreciated.

RNTP version - 4.1.1 Shaka player version - 4.7.13

Screenshot 2024-04-23 at 2 08 50 PM Screenshot 2024-04-23 at 2 05 58 PM
9mzodiac commented 5 months ago

Still stuck on this. Anyone got ideas?

jspizziri commented 5 months ago

@9mzodiac sorry just seeing this. First I'll say that this is technically out of scope for RNTP, as the underlying issue is with Next.js.

However, it just so happens that I know how to fix it. It does depend on the version of next.js that you're using but here's a patch file that works for 13.5.6:

diff --git a/node_modules/next/dist/compiled/@next/react-refresh-utils/dist/internal/ReactRefreshModule.runtime.js b/node_modules/next/dist/compiled/@next/react-refresh-utils/dist/internal/ReactRefreshModule.runtime.js
index 0c26fb6..3894ace 100644
--- a/node_modules/next/dist/compiled/@next/react-refresh-utils/dist/internal/ReactRefreshModule.runtime.js
+++ b/node_modules/next/dist/compiled/@next/react-refresh-utils/dist/internal/ReactRefreshModule.runtime.js
@@ -16,7 +16,7 @@ function default_1() {
             // @ts-ignore __webpack_module__ is global
             var currentExports = __webpack_module__.exports;
             // @ts-ignore __webpack_module__ is global
-            var prevSignature = (_b = (_a = __webpack_module__.hot.data) === null || _a === void 0 ? void 0 : _a.prevSignature) !== null && _b !== void 0 ? _b : null;
+            var prevSignature = (_b = (_a = __webpack_module__.hot?.data) === null || _a === void 0 ? void 0 : _a.prevSignature) !== null && _b !== void 0 ? _b : null;
             // This cannot happen in MainTemplate because the exports mismatch between
             // templating and execution.
             self.$RefreshHelpers$.registerExportsForReactRefresh(currentExports, __webpack_module__.id);

Basically, you need to add that optional check for hot in whatever version of next.js you're on. Eventually this should be reported to next.js upstream but I haven't had the time to do it.

9mzodiac commented 5 months ago

Thank you so much, your solution worked. @jspizziri I am so grateful you helped - my app relies on audio playback for its main feature.