From 2f4a229c5aca621d3ed9c3ce8b9526b1c2e04263 Mon Sep 17 00:00:00 2001 From: Aymeric Rabot Date: Tue, 4 Aug 2026 17:56:08 -0400 Subject: [PATCH] fix(dev): make bun dev work on Windows without dropping the PORT override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ' 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 --- .env.defaults | 11 +++++++++++ .env.example | 4 ++-- apps/editor/package.json | 2 +- package.json | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .env.defaults diff --git a/.env.defaults b/.env.defaults new file mode 100644 index 0000000000..81d2223cfe --- /dev/null +++ b/.env.defaults @@ -0,0 +1,11 @@ +# Committed defaults, loaded last so anything already set wins. +# +# `.env` and `.env.local` are gitignored, so a default cannot live there; and +# `${PORT:-3002}` in a package script is not an option because Bun's own shell +# — which `bun run` uses on Windows — does not implement default-value +# parameter expansion and passes the literal through to Next. +# +# Precedence: shell PORT > .env.local > this file. + +# Dev server port for apps/editor. +PORT=3002 diff --git a/.env.example b/.env.example index daa84046ef..6acbf52100 100644 --- a/.env.example +++ b/.env.example @@ -3,5 +3,5 @@ # Google Maps API key (enables address search) # NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=your_google_maps_api_key -# Dev server port (default: 3000) -# PORT=3000 +# Dev server port (default: 3002, set in .env.defaults) +# PORT=3002 diff --git a/apps/editor/package.json b/apps/editor/package.json index 60baafaaf4..c6c369508b 100644 --- a/apps/editor/package.json +++ b/apps/editor/package.json @@ -4,7 +4,7 @@ "type": "module", "private": true, "scripts": { - "dev": "dotenv -e ../../.env.local -- next dev --port ${PORT:-3002}", + "dev": "dotenv -e ../../.env.local -e ../../.env.defaults -- next dev", "build": "dotenv -e ../../.env.local -- next build", "start": "next start", "lint": "biome lint", diff --git a/package.json b/package.json index 4e2bc8955f..88bb8ea16a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "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", "lint": "biome lint", "lint:fix": "biome lint --write", "format": "biome format --write",