router icon indicating copy to clipboard operation
router copied to clipboard

[start]: preset:bun - Cannot find module "react-dom/server" from "/.output/server/index.mjs"

Open omarkhatibco opened this issue 1 year ago • 1 comments

Describe the bug

When setting the preset to bun in deployment.

the generated bundle is not working, it complains about missing react-dom/server

I checked the node_module inside .output folder, react-dom does not include any exports related to server

Your Example Website or App

https://github.com/omarkhatibco/start-test

Steps to Reproduce the Bug or Issue

run cd apps/web2 then bun run build and bun start

Expected behavior

it should work

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

I was able to replace react-dom manually and get it to work

omarkhatibco avatar Aug 23 '24 16:08 omarkhatibco

@lithdew could you share any of your insights into using Start with Bun?


Edit: Can confirm that bumping react to the canary channel.

bun add react@canary react-dom@canary

This may be a React (react and react-dom) issue with how it interfaces with Bun.

SeanCassiere avatar Aug 24 '24 11:08 SeanCassiere

@SeanCassiere, this still seems to be an issue. I don't think upgrading to the canary release helps if you use react-query, since the current React canary release appears incompatible.

kevmok avatar Apr 12 '25 01:04 kevmok

@SeanCassiere, this still seems to be an issue. I don't think upgrading to the canary release helps if you use react-query, since the current React canary release appears incompatible.

Since this issue was closed, React 19 has been released, so you should not need this workaround anymore.

At the time, if I'm not mistaken, this had to do with ReactDOMServer@18 not having an export for renderToReadableStream, which was present in the canary and eventually is what was pushed to the stable release.

If you've got a reproduction of something broken, please create a new issue with the reproduction and the necessary steps.

At the time, debugging this wasn't the easiest thing, since the monorepo doesn't use Bun and installing the test packages using pr-pkg-new kept on failing for whatever reason 🤷🏼‍♂️

SeanCassiere avatar Apr 12 '25 02:04 SeanCassiere

I'm getting this same error using React 19, Bun & Tanstack start. I haven't tried it yet but I think you could set this up in a fresh Tanstack start project. I assume this is a Bun/React issue and not a Tanstack issue.

$ vinxi start --port 3000

[error] ResolveMessage {} 

[error] Cannot find module 'react-dom/server' from '/usr/src/app/.output/server/index.mjs'

error: script "start" exited with code 1

react and react-dom versions in my package.json

    "react": "19.1.0",
    "react-dom": "19.1.0",

Dockerfile

# Stage 1: Build environment
FROM oven/bun:latest AS base

# Set working directory
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lock drizzle.config.ts /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production


# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENV NODE_ENV=production
RUN bun run build

FROM base AS release
COPY --from=install    /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/package.json .
COPY --from=prerelease /usr/src/app/.output .output
COPY --from=prerelease /usr/src/app/.vinxi .vinxi
COPY --from=prerelease /usr/src/app/drizzle.config.ts .

USER bun
EXPOSE 3000/tcp
ENV HOST=0.0.0.0

CMD ["bun", "start"]

You can build with docker build --pull -t bun-my-app . then run with docker run -d -p 3000:3000 bun-my-app

tomanagle avatar Apr 13 '25 01:04 tomanagle

@tomanagle at least on the alpha branch, this is solved by setting target: bun in vite.config.ts.

export default defineConfig({
    plugins: [
        tanstackStart({target: "bun"}),
    ...

abhiaagarwal avatar Jun 03 '25 02:06 abhiaagarwal