-
Notifications
You must be signed in to change notification settings - Fork 33
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
I can't prerender when using cloudflare or cloudflare-d1 templates #31
Comments
Getting the same in the
It happens with this
|
I am getting the same with the vercel template. |
same problem with : |
Here's how I resolved this issue: my vite.config.ts : import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(({ isSsrBuild }) => ({
plugins: [
reactRouter(),
{
name: "react-router-custom-express-server",
config: () => ({
build: {
rollupOptions: isSsrBuild
? {
input: { "assets/server-build.js": "virtual:react-router/server-build", "index.js": "./server/app.ts" },
output: {
entryFileNames: "[name]",
},
}
: undefined,
},
}),
},
tsconfigPaths(),
],
})); react-router.config.ts : import type { Config } from "@react-router/dev/config";
export default {
// Config options...
// Server-side render by default, to enable SPA mode set this to `false`
ssr: true,
serverBuildFile: "assets/server-build.js", // 🚨 Dont forget this
async prerender() {
return ['/'];
},
} satisfies Config; |
This is also effecting Netlify. Creating a project the latest template and adding
Error:
|
@HatemJerbi's solution wasn't working for me it seemed to just generate two server files, the react-router one and the custom one but wasn't wired up to correctly prerender. Did a little digging on this and I think the source of the problem is that // build/server/assets/server-build-HASH.js
// This build output is what the plugin expects for prerender
export {
serverManifest as assets,
assetsBuildDirectory,
basename,
entry,
future,
isSpaMode,
publicPath,
// Importantly, this routes object
routes,
}; // build/server/index.js
// This is what the prerender is actually looking at, the custom server's config
export {
config,
app as default
}; I'm not sure if the correct solution is to re-export Hacking in my server build filename into the prebuilt vite plugin in // node_modules/@react-router/dev/dist/vite.js
async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
let serverBuildPath = path4.join(
serverBuildDirectory,
"assets/server-build-BKijuY2G.js" // Hacky replacement just to test
);
console.log('serverBuildPath', url.pathToFileURL(serverBuildPath).toString())
let build = await import(url.pathToFileURL(serverBuildPath).toString());
let { createRequestHandler: createHandler } = await import("react-router");
return {
build,
handler: createHandler(build, viteConfig.mode)
};
} |
As mentioned here to include NODE_ENV=production in the build script remix-run/react-router#12508 (comment) it fixed in the default template, but using cloudflare or d1 it still fails.
The error
The text was updated successfully, but these errors were encountered: