Stuck On A Build Error

I've been stuck on the following build error all day.
Preparing app for node-server...
Generated public .output/public
Initializing prerenderer
[vinxi] ℹ Building Nitro Server (preset: nitro-prerender, compatibility date: 2024-11-25)
"@revenuecat/purchases-capacitor" is imported by ".vinxi/build/server-fns/_server/assets/app-CtcriKcd.js", but could not be resolved – treating it as an external dependency.

[vinxi] ✔ Nitro Server built
[nitro] compiled: 0.021ms
[vinxi] ✔ You can preview this build using npx serve .output/public

ERROR nt.init is not a function

at .vinxi/prerender/chunks/nitro/nitro.mjs:1551:14
at ModuleJob.run (node:internal/modules/esm/module_job:273:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:600:26)
at async prerender (node_modules/nitropack/dist/core/index.mjs:1892:44)
at async createBuild (node_modules/vinxi/lib/build.js:376:2)
at async Object.run (node_modules/vinxi/bin/cli.mjs:235:5)
at async runCommand (node_modules/citty/dist/index.mjs:316:16)
at async runCommand (node_modules/citty/dist/index.mjs:307:11)
at async runMain (node_modules/citty/dist/index.mjs:445:7)



ERROR nt.init is not a function
Preparing app for node-server...
Generated public .output/public
Initializing prerenderer
[vinxi] ℹ Building Nitro Server (preset: nitro-prerender, compatibility date: 2024-11-25)
"@revenuecat/purchases-capacitor" is imported by ".vinxi/build/server-fns/_server/assets/app-CtcriKcd.js", but could not be resolved – treating it as an external dependency.

[vinxi] ✔ Nitro Server built
[nitro] compiled: 0.021ms
[vinxi] ✔ You can preview this build using npx serve .output/public

ERROR nt.init is not a function

at .vinxi/prerender/chunks/nitro/nitro.mjs:1551:14
at ModuleJob.run (node:internal/modules/esm/module_job:273:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:600:26)
at async prerender (node_modules/nitropack/dist/core/index.mjs:1892:44)
at async createBuild (node_modules/vinxi/lib/build.js:376:2)
at async Object.run (node_modules/vinxi/bin/cli.mjs:235:5)
at async runCommand (node_modules/citty/dist/index.mjs:316:16)
at async runCommand (node_modules/citty/dist/index.mjs:307:11)
at async runMain (node_modules/citty/dist/index.mjs:445:7)



ERROR nt.init is not a function
It looks like vinxi/nitro is trying to pre-render "@revenuecat/purchases-capacitor" but failing. "@revenuecat/purchases-capacitor" is a client-side SDK. If Start is trying to render this on the server, that would be an issue. That said, I have SSR set to false in app.config.ts. Any help would be appreciated. Happy to provide more context if needed.
19 Replies
Madaxen86
Madaxen862w ago
How do you use the package? Do you initialise the package in onMount?
ChrisThornham
ChrisThornhamOP2w ago
Yes. I also added it to a context provider, which would be initialized outside of the "App." The onMount hasn't been an issue in the past.
Madaxen86
Madaxen862w ago
How to you add it the context? Do you have any code you can share?
ChrisThornham
ChrisThornhamOP2w ago
Of course. Would you like to see the context file?
Tommypop
Tommypop2w ago
Are you intending for the nitro preset to be nitro-prerender? I'd assume that'd solve the issue of it trying to prerender. (though obviously not if it's needed haha)
ChrisThornham
ChrisThornhamOP2w ago
Well, if I'm being fully honest, I'm not even totally sure what nitro-prerender means. I think it means, pre-render what you can on the server. This is a purely client-side application that is using SolidStart and Capacitor JS for mobile apps. So, technically, nothing needs to happen on the server. If I can just turn nitro-prerender off, that would be fine. @Madaxen86 , sorry for the length of that file. This project has become very complex so I added a lot of comments to keep myself straight. Even with npm run dev I'm getting:
TypeError: __vite_ssr_import_0__.default.init is not a function
TypeError: __vite_ssr_import_0__.default.init is not a function
Madaxen86
Madaxen862w ago
I can't spot anything suspicious. I've just remmbered: https://discord.com/channels/722131463138705510/722131463889223772/1196442069334495263 "pre-render" requires SSR. Have you tried to build without pre-render?
ChrisThornham
ChrisThornhamOP2w ago
How do I build without pre-render?
Madaxen86
Madaxen862w ago
don't you have something like
server:{
prerender:{
//...
}
}
server:{
prerender:{
//...
}
}
in your app.config.ts?
ChrisThornham
ChrisThornhamOP2w ago
import { defineConfig } from "@solidjs/start/config";
/* @ts-ignore */
import pkg from "@vinxi/plugin-mdx";

const { default: mdx } = pkg;
export default defineConfig({
ssr: false,
server: {
compressPublicAssets: {
gzip: false,
brotli: false,
}
},
// server: { preset: "vercel" },
extensions: ["mdx", "md"],
vite: {
plugins: [
mdx.withImports({})({
jsx: true,
jsxImportSource: "solid-js",
providerImportSource: "solid-mdx",
}),
],
},
});
import { defineConfig } from "@solidjs/start/config";
/* @ts-ignore */
import pkg from "@vinxi/plugin-mdx";

const { default: mdx } = pkg;
export default defineConfig({
ssr: false,
server: {
compressPublicAssets: {
gzip: false,
brotli: false,
}
},
// server: { preset: "vercel" },
extensions: ["mdx", "md"],
vite: {
plugins: [
mdx.withImports({})({
jsx: true,
jsxImportSource: "solid-js",
providerImportSource: "solid-mdx",
}),
],
},
});
That's my config file
Madaxen86
Madaxen862w ago
Oh yeah, that the "pre-rendering" of the index.html weird that it this throws the error. Going on from here you could: 1. try to use clientOnly to import the component which uses the revenuecat pkg. 2. tweak vite config. (Don't know about this one tbh. Maybe noExternal:["@revenuecat/purchases-capacitor"])
ChrisThornham
ChrisThornhamOP2w ago
Ok, thank you. I'll keep troubleshooting.
Tommypop
Tommypop2w ago
You could also do a dynamic import in onMount and store it in a signal or something (or maybe a clientOnly resource). Should have the same effect as using clientOnly for the component but might prevent any weirdness with it getting bundled on the server
Tommypop
Tommypop2w ago
Maybe something like this could work? (It's a little weird but hopefully would stop any bundling stuff breaking things) https://playground.solidjs.com/anonymous/acc9dc0a-894d-43b1-baa6-278807e84998
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
ChrisThornham
ChrisThornhamOP2w ago
I solved it. I was importing the SupabaseAuthContext outside of a component. 🤦‍♂️ That took about 7 hours to solve. It would be helpful if the error referenced the file causing the problem. It may be something to consider for the DX team. Thanks @Madaxen86 and @Tommypop for helping me narrow down this error.
Madaxen86
Madaxen862w ago
I usually write the useContext like this:
const useMyContext = () => {
const ctx = useContext(MyContext);
if (!ctx) throw new Error("useMyContext must be called inside MyContext.Provider.");
return ctx;
}
const useMyContext = () => {
const ctx = useContext(MyContext);
if (!ctx) throw new Error("useMyContext must be called inside MyContext.Provider.");
return ctx;
}
This way the context is never null/undefined and it prevents me from using it outside of the scope.
Tommypop
Tommypop2w ago
Yeah, I wonder if there could be a dev warning in dev if the context is undefined. Might make a PR for it and see what happens I've made a PR https://github.com/solidjs/solid/pull/2466. Not sure if it's at all necessary but the change was pretty simple so thought I may as well do it and hopefully it'd prevent issues like this in the future :)
ChrisThornham
ChrisThornhamOP2w ago
@Tommypop MUCH appreciated. Thank you.

Did you find this page helpful?