You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor Next.js adapter to include defineNextPublicEnv for client-only environment validation, update README for installation instructions, and ensure consistent dependency management across packages. Adjust contributing guidelines for clarity.
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,12 +47,12 @@ We **do not** use `NPM_TOKEN` in GitHub Actions. Releases use [npm Trusted Publi
47
47
48
48
Trusted Publisher is configured **per package** on npm, but the **link is to one GitHub repo + one workflow file** (`release.yml`). For this repo you repeat the same publisher setup for each published package:
Other libraries validate well; envra adds **generated docs**, **`.env.example` sync**, **`doctor` hygiene**, and a **rich result object** (`values`, `get`, `has`, `meta`) instead of a plain map.
44
44
@@ -101,12 +101,12 @@ Export `defineEnv` as `default` / `env`, or export field builders as `schema`, `
101
101
102
102
**`--json`** on `check` / `doctor` prints machine-readable output for CI.
|`@envra/next`|`defineNextEnv` / `defineNextPublicEnv`; **peer**`@envra/core` — see [packages/next/README](packages/next/README.md)|
120
120
|`@envra/eslint-plugin`|`envra/no-process-env`|
121
121
122
+
Install Next adapter with **`pnpm add @envra/next @envra/core`** so one `@envra/core` version is used (avoids TypeScript `FieldBuilder` clashes). On pnpm, use `overrides` if duplicates appear — [packages/next/README.md](packages/next/README.md#pnpm--duplicate-envracore).
Copy file name to clipboardExpand all lines: packages/next/README.md
+49-4Lines changed: 49 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,14 @@ Next.js adapter for [envra](https://github.com/hasansmadix/envra): split **serve
5
5
## Install
6
6
7
7
```bash
8
-
pnpm add @envra/next
8
+
pnpm add @envra/next @envra/core
9
9
# or
10
-
npm install @envra/next
10
+
npm install @envra/next @envra/core
11
11
```
12
12
13
-
Peer:`next` >= 14 (optional peer for typing; install `next`in your app).
13
+
**Peers:**`next` >= 14 (optional for typing in non-Next contexts), **`@envra/core` ^0.1.2** (install explicitly so a single copy is used — avoids duplicate `FieldBuilder` types in TypeScript).
For secrets and server-only variables, keep a separate module with `import "server-only"` and `defineNextEnv` (or `defineEnv` from `@envra/core`).
47
+
48
+
## Next.js App Router: server vs client modules
49
+
50
+
1.**Server env** — e.g. `lib/env.ts` with `import "server-only"` at the top, then `defineNextEnv` with both `server` and `client` (or server-only schema via `@envra/core`).
51
+
2.**Public env** — e.g. `lib/env-public.ts`**without**`server-only`, using `defineNextPublicEnv` or only the `client` block patterns above.
52
+
3.**Do not** import the server env module from code that is bundled for the client (Client Components, or shared `services/` / `lib/` pulled in by them). Use `publicEnv` for anything that needs env inside client bundles.
53
+
54
+
## pnpm / duplicate `@envra/core`
55
+
56
+
If TypeScript reports that `FieldBuilder` types are incompatible (*separate declarations of a private property*), you likely have **two versions** of `@envra/core` installed. Fix with a single version, for example:
57
+
58
+
```json
59
+
{
60
+
"pnpm": {
61
+
"overrides": {
62
+
"@envra/core": "0.1.2"
63
+
}
64
+
}
65
+
}
66
+
```
67
+
68
+
## Re-exports
69
+
70
+
`@envra/next` re-exports common builders (`str`, `int`, `secret`, …), **`FieldBuilder`**, **`InferSchema`**, and `defineEnv` from `@envra/core` so you can use **one import path** in Next apps:
0 commit comments