TanStack / TanStack/router

NODE_ENV='development' produces broken builds with nitro

Open
#6,484 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

If NODE_ENV is set to 'development' at build time, the build command will succeed and the resulting server process can start, but all requests result in 500s with baffling error messages.

I think this is related to the new static NODE_ENV compilation feature. Affects 1.154 - 1.157

Fix for users

Unset NODE_ENV='development' when building. I wouldn't call it a 'workaround' as building for
production with that set doesn't really make sense, but the cause of the problem is not obvious. I
had set it in .env awhile ago for some reason or other that I can't remember, and lost a few hours
chasing this issue down. (Admittedly a skill issue but still)

Error text

Hopefully help anyone googling the issue find this:

❯ node .output/server/index.mjs 
➜ Listening on: http://localhost:3000/ (all interfaces)
TypeError: jsxDevRuntimeExports.jsxDEV is not a function
    at RootDocument (file:///home/robert/development/tmp/tsstart-repo/.output/server/_ssr/router-DgVFqghq.mjs:97:106)
    at renderWithHooks (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8447:20)
    at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8521:16)
    at retryNode (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:9064:18)
    at renderNodeDestructive (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8910:237)
    at finishFunctionComponent (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8465:234)
    at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8523:9)
    at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8843:13)
    at retryNode (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:9064:18)
    at renderNodeDestructive (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8910:237)
TypeError: jsxDevRuntimeExports.jsxDEV is not a function
    at RootDocument (file:///home/robert/development/tmp/tsstart-repo/.output/server/_ssr/router-DgVFqghq.mjs:97:106)
    ... 8 lines matching cause stack trace ...
    at renderNodeDestructive (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8910:237) {
  cause: TypeError: jsxDevRuntimeExports.jsxDEV is not a function
      at RootDocument (file:///home/robert/development/tmp/tsstart-repo/.output/server/_ssr/router-DgVFqghq.mjs:97:106)
      at renderWithHooks (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8447:20)
      at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8521:16)
      at retryNode (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:9064:18)
      at renderNodeDestructive (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8910:237)
      at finishFunctionComponent (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8465:234)
      at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8523:9)
      at renderElement (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8843:13)
      at retryNode (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:9064:18)
      at renderNodeDestructive (file:///home/robert/development/tmp/tsstart-repo/.output/server/_chunks/_libs/react-dom.mjs:8910:237),
  status: 500,
  statusText: undefined,
  headers: undefined,
  data: undefined,
  body: undefined,
  unhandled: true
}
Your Example Website or App

https://github.com/rbuchberger/tsstart-build-bug

Steps to Reproduce the Bug or Issue
  • Create new TSStart app, version 1.154.x (Not sure about 1.155-1.157)
  • Set NODE_ENV='development' (possibly in an env file, as in this repo)
  • pnpm build
  • Build succeeds, appears normal.
  • node .output/server/index.mjs
  • Visit localhost:3000
  • Get a 500 error in the browser, and TypeError: jsxDevRuntimeExports.jsxDEV is not a function in
    the server console. Changing NODE_ENV at this point makes no difference.

While troubleshooting, I also encountered errors related to missing dependencies. I presume the
dependencies themselves were stripped out, but the code which calls them wasn't.

Expected behavior

Anything other than waiting till the first request comes in at runtime to fail with a baffling error.

  • Refuse to build with NODE_ENV='development' with a clear error message.
  • Create a working build, without a static NODE_ENV and a console warning.
  • Disregard and create a working build, along with a console warning.
  • Honor and create a working build, with a console warning that the produced build is statically
    compiled into development mode.
Screenshots or Videos
Image Image
Platform
  • Router / Start Version: 1.154.13
  • OS: Linux
  • Browser: Any
  • Bundler: Vite + Nitro
  • Bundler Version: Vite 7.1.7, nitro-nightly 3.0.1
Additional context

Just wanna say thanks for an awesome project and all the work y'all do!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and reproduce the failure using pnpm build, then run .output/server/index.mjs with NODE_ENV='development'. Investigate the static NODE_ENV compilation behavior described in the issue and verify that a build either fails clearly or produces a working server with an appropriate warning instead of the reported 500 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript, vite
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.