devtools don't work with Bun: Avoid using NODE_ENV in devtools server code
#11796
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
when running the
devtoolsbin with bun usingbunx --bun devtoolsin user's codebase, the lib doesn't work properly and runs in dev mode for the user if they have a.envfile with the valueNODE_ENVset todevelopmentbecause bun auto loads the user's vars from the.envfile. I don't think its wise to use environment variables in libraries' code because users' environments can affect the runtime behaviour, especially so for popular runtime variables such asNODE_ENV.I also noticed that the
devToolsMiddlewarefunction also usesNODE_ENVto throw an error if the user using this in production. i think the same reasoning against env vars in libraries' code applies again, but its less harmful here.I checked that this fix works but pointing to the local build for the devtools code from my own project where i encountered the code and made sure that
bunx --bun devtoolsworks (not in dev mode) even if i have a .env file withNODE_ENVset todevelopment.Checklist
pnpm changesetin the project root)