Skip to content

Conversation

@bassgeta
Copy link
Contributor

@bassgeta bassgeta commented Oct 9, 2025

Problem

#149 broke the build because it introduced new .js files for environment validation.

Solution

Change the 3 environment validation files from .js to .mjs so they're processed as JS Modules (import/export syntax), not CommonJS (requires syntax).

image

And it works 🎉

Summary by CodeRabbit

  • Chores
    • Build now supports an optional skip for environment validation, giving flexibility for CI/CD and local builds.
    • Startup environment checks respect the skip flag while preserving default validation behavior.
    • Internal module resolution and config updates to support ES module files — no user-facing changes or UI impact.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adds SKIP_ENV_VALIDATION=true to the build script, switches several environment-related imports and files to .mjs, conditions client/server env validation in next.config.mjs on that variable, updates tsconfig includes to .mjs files, and exports the Next.js config default.

Changes

Cohort / File(s) Summary
Build script
package.json
scripts.build changed from next build to SKIP_ENV_VALIDATION=true next build.
Next config & env validation
next.config.mjs
Imports switched to .mjs, added export default nextConfig, and wrapped validateServerEnv() / validateClientEnv() to run only when process.env.SKIP_ENV_VALIDATION !== "true".
Env modules (client/server/helpers)
src/lib/env/*.mjs
Updated import paths/extensions to .mjs (e.g., ./helpers.js./helpers.mjs) in client.mjs, server.mjs, and related helper file(s). No API changes.
TypeScript config
tsconfig.json
include updated from src/lib/env/*.js to explicit .mjs entries (e.g., src/lib/env/client.mjs, src/lib/env/helpers.mjs, src/lib/env/server.mjs).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant CLI as npm/yarn
  participant Next as Next Build
  participant Config as next.config.mjs
  participant Env as Env validators (server/client)

  Dev->>CLI: run build
  CLI->>Next: SKIP_ENV_VALIDATION=true next build
  Next->>Config: load next.config.mjs
  alt SKIP_ENV_VALIDATION !== "true"
    Config->>Env: validateServerEnv()
    Config->>Env: validateClientEnv()
    Env-->>Config: validation results
  else SKIP_ENV_VALIDATION === "true"
    Note right of Config #cfe2ff: env validation skipped
  end
  Config-->>Next: config ready
  Next-->>Dev: build output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rodrigopavezi
  • aimensahnoun
  • MantisClone

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title is too vague and informal, using "fix it" and an emoji without specifying what change addresses the build issue, so it doesn’t clearly convey the main fix of renaming validation files to .mjs to resolve the build break. Please update the title to clearly describe the primary change, for example “build: rename env validation files to .mjs to fix build break,” and remove informal elements like emojis.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/build-issues

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d37988f and 0610b3e.

📒 Files selected for processing (1)
  • tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tsconfig.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
package.json (1)

8-8: Consider cross-platform compatibility for environment variables.

The syntax SKIP_ENV_VALIDATION=true next build works on Unix-like systems (Linux, macOS) but will fail on Windows. Consider using the cross-env package for cross-platform compatibility.

First, install cross-env as a dev dependency:

npm install --save-dev cross-env

Then apply this diff to make the build script cross-platform:

-    "build": "SKIP_ENV_VALIDATION=true next build",
+    "build": "cross-env SKIP_ENV_VALIDATION=true next build",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1146212 and fbdb8f7.

📒 Files selected for processing (2)
  • next.config.mjs (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
next.config.mjs (2)
src/lib/env/server.js (1)
  • validateServerEnv (33-64)
src/lib/env/client.js (1)
  • validateClientEnv (14-39)
🪛 GitHub Actions: Build and Lint
next.config.mjs

[error] 1-1: SyntaxError: The requested module './src/lib/env/client.js' does not provide an export named 'default'. Build failed while loading next.config.mjs during 'npm run build'.

🔇 Additional comments (1)
next.config.mjs (1)

7-10: LGTM! Conditional validation logic is correct.

The guard correctly skips environment validation when SKIP_ENV_VALIDATION is set to "true", which aligns with the build script change in package.json.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
next.config.js (1)

4-7: Consider removing redundant skip logic.

The conditional block works correctly. However, based on the relevant code snippets, both validateServerEnv() and validateClientEnv() already call shouldSkipValidation() internally and return early with a warning if validation should be skipped. This creates two layers of the same check.

Consider one of these approaches:

Option 1 (Recommended): Remove the outer conditional and rely solely on the validation functions' internal skip logic:

-if (process.env.SKIP_ENV_VALIDATION !== "true") {
-  validateServerEnv();
-  validateClientEnv();
-}
+validateServerEnv();
+validateClientEnv();

Option 2: If the outer check serves a different purpose (e.g., avoiding import side effects), keep it but document why both layers exist.

This simplification would improve maintainability by keeping the skip logic in one place and reducing potential confusion for future developers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbdb8f7 and 084f3d9.

📒 Files selected for processing (1)
  • next.config.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
next.config.js (2)
src/lib/env/server.js (1)
  • validateServerEnv (33-64)
src/lib/env/client.js (1)
  • validateClientEnv (14-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
next.config.js (1)

1-2: LGTM!

The import statements are correct and properly reference the validation functions with explicit .js extensions.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
next.config.mjs (1)

4-7: Redundant validation skip check.

Both validateServerEnv and validateClientEnv internally call shouldSkipValidation() at their start (see src/lib/env/server.js lines 33-36 and src/lib/env/client.js lines 14-17), making this outer conditional check redundant. While defensive, this duplication means the skip logic exists in two places.

Consider one of these approaches:

  1. Remove the outer conditional and rely solely on the internal checks within the validation functions.
  2. Keep the outer conditional and remove the internal shouldSkipValidation() checks to centralize the logic here.

Additionally, the string comparison !== "true" is strict. Values like "TRUE", "1", or "yes" won't skip validation. If broader flexibility is desired, consider a case-insensitive check or accepting multiple truthy values.

Based on relevant code snippets from src/lib/env/server.js and src/lib/env/client.js.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2efb232 and 3465791.

📒 Files selected for processing (2)
  • next.config.mjs (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🧬 Code graph analysis (1)
next.config.mjs (2)
src/lib/env/server.js (1)
  • validateServerEnv (33-64)
src/lib/env/client.js (1)
  • validateClientEnv (14-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
next.config.mjs (1)

1-2: Import syntax correctly fixed.

The named imports now match the exports from the validation modules, addressing the previous build failure.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tsconfig.json (1)

29-31: Consider switching back to a glob for env files. Explicit listing is accurate but will require manual updates whenever new .mjs files are added; using "src/lib/env/*.mjs" ensures future files are picked up automatically.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3465791 and d37988f.

📒 Files selected for processing (4)
  • next.config.mjs (1 hunks)
  • src/lib/env/client.mjs (1 hunks)
  • src/lib/env/server.mjs (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
next.config.mjs (2)
src/lib/env/server.mjs (1)
  • validateServerEnv (33-64)
src/lib/env/client.mjs (1)
  • validateClientEnv (14-39)
🔇 Additional comments (4)
src/lib/env/client.mjs (1)

2-2: LGTM!

The import path update to .mjs extension is correct and aligns with the ES module migration across the codebase.

src/lib/env/server.mjs (1)

2-2: LGTM!

The import path update to .mjs extension is consistent with the ES module migration.

next.config.mjs (2)

1-7: LGTM!

The import paths have been correctly updated to .mjs extensions, and the conditional validation logic properly guards environment checks during build when SKIP_ENV_VALIDATION=true. This addresses the previous build failure.


12-12: LGTM!

The default export is now properly configured.

@bassgeta bassgeta changed the title build: rework imports according to error logs, skip env validation when building build: fix it :D Oct 9, 2025
Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bassgeta Approved 👍 Pending comment resolution 🚧

The PR Description does not adequately explain the problem and is missing details about the solution.

Something like:

# Problem
#149 broke the build because it introduced new .js files for environment validation.

# Solution
Change the 3 environment validation files from `.js` to `.mjs` so they're processed as JS Modules (`import`/`export` syntax), not CommonJS (`requires` syntax).

# Bonus
Added option to skip environment validation for local development

@bassgeta bassgeta merged commit a038333 into main Oct 10, 2025
5 checks passed
@bassgeta bassgeta deleted the fix/build-issues branch October 10, 2025 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants