Error when evaluating SSR module EVEN WITH ssr: false

I have a SolidStart project with file-based routing and ssr: false I'm using @revenuecat/purchases-capacitor inside of the project. When I use the revenuecat package in a file inside of the routes folder, everything works. Unfortunately, using the revenuecat package outside of the routes folder throws and error: Error when evaluating SSR module /node_modules/@solidjs/start/dist/server/spa/handler.js: failed to import "@revenuecat/purchases-capacitor" I'm guessing that's because SolidStart only considers files inside of the routes folder to be "client side" even if I have ssr: false. Is this a correct assumption? Any clarity would be appreciated. For context, I was trying to use the revenuecat package in an auth-context file that I provide to the app like this:
<Router
root={(props) => (
<MetaProvider>
<SupabaseAuthProvider> // I'M USING THE REVENUECAT PACKAGE HERE
<ThemeProvider>
<DeviceProvider>
<Title>{brandName}</Title>
<PostHogPageView />
<Suspense>{props.children}</Suspense>
</DeviceProvider>
</ThemeProvider>
</SupabaseAuthProvider>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
<Router
root={(props) => (
<MetaProvider>
<SupabaseAuthProvider> // I'M USING THE REVENUECAT PACKAGE HERE
<ThemeProvider>
<DeviceProvider>
<Title>{brandName}</Title>
<PostHogPageView />
<Suspense>{props.children}</Suspense>
</DeviceProvider>
</ThemeProvider>
</SupabaseAuthProvider>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
Thanks!
1 Reply
ChrisThornham
ChrisThornhamOP2mo ago
If anyone runs into a similar issue in the future, here's the fix. When working with RevenueCat, you have to initialize the service once, preferably at a "high" level in the app. I chose to initialize the service in app.tsx. However, context files cannot access RevenueCat when you initialize the service in app.tsx. Moving any required RevenueCat code inside of a route fixed the problem. I don't know why this happens; it likely has something to do with timing, but this is the solution.

Did you find this page helpful?