Skip to content
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

React SSR not working in Production Build. #8449

Closed
7 tasks done
Trackhe opened this issue Jun 2, 2022 · 8 comments
Closed
7 tasks done

React SSR not working in Production Build. #8449

Trackhe opened this issue Jun 2, 2022 · 8 comments

Comments

@Trackhe
Copy link

Trackhe commented Jun 2, 2022

Describe the bug

I managed to get SSR with React and Vite working with the command "vite" but when i try to build with "vite build" and serve it with "vite preview" SSR got not working.
The code is Public and i want to Maintain it as a good template: https://github.com/Trackhe/Vite-React-SSR-HMR

Reproduction

Reproduction clone my code, then npm i -> npm run dev try all works. shutdown and try npm run preview, look in the loaded document now no SSR

System Info

System:
    OS: macOS 12.4
    CPU: (20) arm64 Apple M1 Ultra
    Memory: 19.76 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.0.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.10.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-react: * => 1.3.2 
    vite: * => 2.9.9

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

configureServer only runs when using vite and it does not run with vite preview.
Are you looking for #7658 ?

@Trackhe
Copy link
Author

Trackhe commented Jun 3, 2022

maybe yes, but this dosn't work. It builds but change nothing.

@Trackhe
Copy link
Author

Trackhe commented Jun 3, 2022

I had to choose the 3.0.0-alpha.9 version to get the configurePreviewServer running, but in that call is server.ssrLoadModule is not a function

i understand why it is there, as it mentioned in the docs there: https://vitejs.dev/guide/ssr.html#setting-up-the-dev-server

"Instead of await vite.ssrLoadModule('/src/entry-server.js'), use require('./dist/server/entry-server.js') instead (this file is the result of the SSR build)"

but this seems not suitable for streaming.

@sapphi-red
Copy link
Member

What do you mean by "not suitable for streaming"?

@Trackhe
Copy link
Author

Trackhe commented Jun 4, 2022

What do you mean by "not suitable for streaming"?

Because i use the ssr over streaming in react 18 and when i cant use loadssrmodule in the preview server it might be not working. I tried it shortly but only with require as it mentioned in the docu, i cant get it working. So maybe i need to setup an extra node express server for that. I m correct?

@sapphi-red
Copy link
Member

Streaming works with require/import, it does not need to be run with ssrLoadModule.

@Trackhe
Copy link
Author

Trackhe commented Jun 4, 2022

When i try that i got errors like no loader for .svg is configured and when i comment that out
TypeError: server.transformIndexHtml is not a function
and there is where i dont know to continue.

@bluwy
Copy link
Member

bluwy commented Jun 5, 2022

I'll close this as it doesn't seem to be a bug in Vite, but more of a usage issue. Re configurePreviewServer, the feature has been backported to the v2 branch and will make it's way in 2.9.10 when it's released.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants