new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

configuration & environment

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Bun does not load .env automatically with --bun flag

Bun does not load `.env` automatically when running a CLI with the `--bun` flag. The `--env-file=.env` flag must be passed explicitly to read environment variables.

Environment variables in bunfig.toml registry configuration

bunfig.toml can reference environment variables in the registry configuration. For example: registry = { url = "https://registry.npmjs.org", token = "$npm_token" }. The bun install command automatically loads environment variables from .env.production.local, .env.local, .env.production, and .env files, regardless of NODE_ENV. It does not read .env.development or .env.test files.

.env file loading order and precedence

Bun automatically reads environment variables from .env files in the following order of increasing precedence: (1) .env, (2) .env.production, .env.development, or .env.test depending on the NODE_ENV value, (3) .env.local (not loaded when NODE_ENV=test), (4) .env.production.local, .env.development.local, or .env.test.local depending on the NODE_ENV value. Files loaded later override earlier files.

Set environment variables via command line on Linux/macOS

On Linux and macOS, environment variables can be set on the command line by prefixing the command with the variable assignment. For example, `FOO=helloworld bun run dev` sets the FOO variable to helloworld before running the dev command.

Set environment variables via command line on Windows

On Windows, environment variables can be set on the command line using two methods. With CMD: `set FOO=helloworld && bun run dev`. With PowerShell: `$env:FOO="helloworld"; bun run dev`.

.env file syntax

Environment variables in .env files are defined using the format KEY=value, one per line. For example, FOO=hello and BAR=world define two environment variables.

TypeScript configuration for Bun

The recommended tsconfig.json settings for Bun include: lib: ["ESNext"], target: "ESNext", module: "Preserve", moduleDetection: "force", moduleResolution: "bundler", allowImportingTsExtensions: true, verbatimModuleSyntax: true, noEmit: true. These enable proper TypeScript support and editor autocomplete in Bun projects.

TypeScript 6.0 changed type discovery - types field now empty by default

Starting in TypeScript 6.0, the `types` field in `compilerOptions` defaults to an empty array instead of including all `@types/*` packages automatically. You now need to explicitly list the type packages you use.

Add types field to tsconfig.json for Bun types

To use Bun's type definitions with TypeScript 6.0 or later, add `"types": ["bun"]` to `compilerOptions` in your tsconfig.json. If you use other `@types/*` packages, include them in the same array, for example: `"types": ["bun", "react"]`.

Full recommended tsconfig.json for Bun with TypeScript 6.0+

{ "compilerOptions": { "lib": ["ESNext"], "target": "ESNext", "module": "Preserve", "moduleDetection": "force", "jsx": "react-jsx", "allowJs": true, "types": ["bun"], "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "noEmit": true, "strict": true, "skipLibCheck": true, "noFallthroughCasesInSwitch": true, "noUncheckedIndexedAccess": true, "noImplicitOverride": true, "noUnusedLocals": false, "noUnusedParameters": false, "noPropertyAccessFromIndexSignature": false } }

TypeScript 7 has same type discovery changes as TypeScript 6

TypeScript 7 carries forward the same default as TypeScript 6.0 where the `types` field in `compilerOptions` defaults to an empty array. If upgrading directly from TypeScript 5 to 7, the same fix applies — add `"types": ["bun"]` to your `compilerOptions`.

Give your agent this brain