fix(dev): make bun dev work on Windows without dropping the PORT override - #587
Merged
Conversation
…ride
Two package scripts use POSIX shell syntax that Bun's own shell does not
implement, and Bun uses that shell for `bun run` on Windows:
- `apps/editor`'s dev script passes `--port ${PORT:-3002}`, which arrives at
Next verbatim: `option '-p, --port <port>' argument '${PORT:-3002}' is
invalid`. Setting PORT does not help — the literal is never expanded.
- the root dev script starts `set -a && . ./.env`, and `set` is not a Bun
shell builtin, so it prints `bun: command not found: set` and silently
skips loading `.env` entirely.
Reproduced both on macOS with `bun run --shell=bun`, which selects the same
shell Windows gets:
$ echo port=${PORT:-3002}
port=${PORT:-3002} # even with PORT=9999 in the environment
$ set -a && echo set-worked
bun: command not found: set
Hardcoding the port would fix Windows but drop the PORT override that
SETUP.md and .env.example both document. Instead, load a committed
`.env.defaults` last and let `next dev` read PORT from the environment
(the CLI already declares `.env('PORT')` on `-p, --port`). Nothing is
shell-expanded, so it behaves the same on every platform, and the
precedence stays shell PORT > .env.local > .env.defaults — verified at
3002 by default and 4321 with an override, under both shells.
`.env.defaults` is needed because `.env` and `.env.local` are gitignored,
so a checked-in default has nowhere else to live.
Also corrects `.env.example`, which advertised a 3000 default the repo has
not used since the port moved to 3002.
Reported by @evolv3ai in #551, including the Windows console output and the
`set` finding.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2f4a229. Configure here.
| "scripts": { | ||
| "build": "turbo run build", | ||
| "dev": "set -a && . ./.env 2>/dev/null; set +a; turbo run dev --env-mode=loose", | ||
| "dev": "dotenv -e ./.env -e ./.env.defaults -- turbo run dev --env-mode=loose", |
There was a problem hiding this comment.
Root defaults block local PORT
Medium Severity
The dev script loads .env.defaults via dotenv-cli before the editor application starts. This causes PORT values from .env.local to be ignored by the editor, as dotenv-cli does not override existing environment variables, breaking the intended precedence.
Reviewed by Cursor Bugbot for commit 2f4a229. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Fixes the Windows dev-server breakage reported in #551, keeping the
PORToverride that bothSETUP.mdand.env.exampledocument.The bugs
Two package scripts use POSIX shell syntax Bun's own shell doesn't implement — and Bun uses that shell for
bun runon Windows:apps/editordev script passes--port ${PORT:-3002}, which reaches Next verbatim:set -a && . ./.env, andsetisn't a Bun shell builtin — it printsbun: command not found: setand silently skips loading.envaltogether.Both reproduce on macOS with
bun run --shell=bun, which selects the same shell Windows gets:Worth noting the second one is a silent failure:
turbostill runs, so on Windows the root.envhas simply never been loaded and nothing said so.The fix
Hardcoding
--port 3002fixes Windows but drops the documentedPORToverride. Instead, load a committed.env.defaultslast and letnext devreadPORTfrom the environment — its CLI already declares.env('PORT')on the-p, --portoption:Nothing is shell-expanded, so behaviour is identical on every platform.
.env.defaultsexists because.envand.env.localare gitignored — a checked-in default has nowhere else to live.No
--hostnameis added: Next deliberately passes no default host, Node then binds::dual-stack, and pinning0.0.0.0would makehttp://[::1]:3002unreachable.Verification
Precedence is shell
PORT>.env.local>.env.defaults, confirmed under both shells:--shell=bun(Windows path)http://localhost:3002PORT=4321--shell=bunhttp://localhost:4321http://localhost:3002bun dev--shell=buncommand not found: setGates:
checkclean (1600 files) ·check-types9/9 ·test1881 pass / 0 fail ·build7/7.Also corrects
.env.example, which advertised a 3000 default the repo hasn't used since the port moved to 3002.Credit
Reported by @evolv3ai in #551, including the Windows console output and the
setfinding — both reproduced here. That PR also proposed two other changes; #578 has since fixed the autosave-guard one at the hook layer, and the third turned out to be a non-issue (apps/editor/next.config.tsalready redirects/editor/:id→/scene/:id).Supersedes #551.
🤖 Generated with Claude Code
Note
Low Risk
Dev-only script and env loading changes; no runtime app logic, auth, or production deployment paths affected.
Overview
Fixes Windows
bun rundev failures caused by POSIX-only shell syntax in package scripts.Editor dev no longer passes
--port ${PORT:-3002}(Bun’s shell leaves that literal and breaks Next). It now runsdotenvwith../../.env.localand../../.env.defaults, thennext dev, soPORTcomes from the environment (default 3002 in the committed defaults file).Root
bun devno longer usesset -a && . ./.env(unsupported on Bun’s Windows shell, which silently skipped loading.env). It usesdotenv -e ./.env -e ./.env.defaultsbeforeturbo run dev.Adds
.env.defaultsdocumenting precedence: shellPORT>.env.local> defaults..env.exampleis updated to document port 3002 instead of 3000.Reviewed by Cursor Bugbot for commit 2f4a229. Bugbot is set up for automated code reviews on this repo. Configure here.