Skip to content

fix(core): Ensure single zod instance across workspace packages#28604

Merged
lucamattiazzi merged 5 commits intomasterfrom
CAT-2822-npx-n8n-fails
Apr 20, 2026
Merged

fix(core): Ensure single zod instance across workspace packages#28604
lucamattiazzi merged 5 commits intomasterfrom
CAT-2822-npx-n8n-fails

Conversation

@lucamattiazzi
Copy link
Copy Markdown
Contributor

Summary

Ensures that zod always has the same version across all packages. Also fixes error message suppression in module import.
Since stable presents the bug, we might want to backport it.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CAT-2822

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

@lucamattiazzi lucamattiazzi requested a review from Matsuuu April 17, 2026 08:59
@lucamattiazzi lucamattiazzi marked this pull request as ready for review April 17, 2026 09:02
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...@n8n/backend-common/src/modules/module-registry.ts 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

Architecture diagram
sequenceDiagram
    participant Registry as ModuleRegistry
    participant Loader as NodeJS import()
    participant Zod as Shared Zod Instance
    participant Mod as Module (Primary/EE)
    participant Err as MissingModuleError

    Note over Registry,Zod: Module Initialization & Zod Singleton Enforcement

    loop for each moduleName
        Registry->>Loader: import(primaryPath)
        
        activate Loader
        Loader->>Zod: Resolve Zod Reference
        Note over Loader,Zod: CHANGED: peerDependencies ensure<br/>workspace-wide singleton instance
        
        alt Primary module exists
            Loader->>Mod: Initialize
            Mod-->>Loader: Module Exports
            Loader-->>Registry: Success (Continue loop)
        else NEW: Error is NOT 'MODULE_NOT_FOUND'
            Loader-->>Registry: Throw logic/syntax error
            Registry->>Err: NEW: Wrap with full stack trace
            Err-->>Registry: Detailed Error
            Note right of Registry: PR fixes error suppression
        else Primary module NOT found
            Loader-->>Registry: MODULE_NOT_FOUND
            deactivate Loader
            
            Registry->>Loader: import(eePath)
            activate Loader
            alt EE module exists
                Loader->>Mod: Initialize
                Mod-->>Loader: Module Exports
                Loader-->>Registry: Success
            else EE module NOT found
                Loader-->>Registry: MODULE_NOT_FOUND
                Registry->>Err: Throw MissingModuleError
            else NEW: EE load fails with logic error
                Loader-->>Registry: Throw logic/syntax error
                Registry->>Err: NEW: Report EE error instead of primary
            end
            deactivate Loader
        end
    end
Loading

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

Performance Comparison

Comparing currentlatest master14-day baseline

PR perf tests not yet enabled. Current = latest master run.

Memory consumption baseline with starter plan resources

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-heap-used-baseline 114.81 MB 114.81 MB 114.31 MB (σ 0.45) +0.0% +0.4% ⚠️
memory-rss-baseline 281.90 MB 281.90 MB 294.91 MB (σ 43.60) +0.0% -4.4%

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-runners 386.00 MB 386.00 MB 390.73 MB (σ 9.55) +0.0% -1.2%
docker-image-size-n8n 1269.76 MB 1269.76 MB 1269.76 MB (σ 0.00) +0.0% +0.0%

Idle baseline with Instance AI module loaded

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 186.26 MB 186.26 MB 186.38 MB (σ 0.24) +0.0% -0.1%
instance-ai-rss-baseline 380.55 MB 380.55 MB 362.64 MB (σ 22.54) +0.0% +4.9%
How to read this table
  • Current: This PR's value (or latest master if PR perf tests haven't run)
  • Latest Master: Most recent nightly master measurement
  • Baseline: Rolling 14-day average from master
  • vs Master: PR impact (current vs latest master)
  • vs Baseline: Drift from baseline (current vs rolling avg)
  • Status: ✅ within 1σ | ⚠️ 1-2σ | 🔴 >2σ regression

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/@n8n/backend-common/src/modules/module-registry.ts">

<violation number="1" location="packages/@n8n/backend-common/src/modules/module-registry.ts:99">
P1: Only fall back to EE import when the primary import is actually module-not-found; otherwise unexpected primary import errors can be silently masked.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread packages/@n8n/backend-common/src/modules/module-registry.ts
@lucamattiazzi lucamattiazzi enabled auto-merge April 17, 2026 11:43
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Bundle Report

Bundle size has no change ✅

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/worker-*.js -3.15MB 17.9kB -99.43%
assets/worker-*.js 3.15MB 3.17MB 17586.03% ⚠️

@lucamattiazzi lucamattiazzi requested review from Matsuuu, ivov and yehorkardash and removed request for Matsuuu April 20, 2026 07:56
@n8n-assistant n8n-assistant Bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Apr 20, 2026
Copy link
Copy Markdown
Member

@ivov ivov left a comment

Choose a reason for hiding this comment

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

Consider also pnpm overrides, in case some future transitive dep drags in a different zod version.

@lucamattiazzi lucamattiazzi added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lucamattiazzi lucamattiazzi added this pull request to the merge queue Apr 20, 2026
@lucamattiazzi lucamattiazzi removed this pull request from the merge queue due to a manual request Apr 20, 2026
@lucamattiazzi lucamattiazzi added this pull request to the merge queue Apr 20, 2026
Merged via the queue into master with commit 107c48f Apr 20, 2026
92 of 96 checks passed
@lucamattiazzi lucamattiazzi deleted the CAT-2822-npx-n8n-fails branch April 20, 2026 17:23
@dlavrenuek dlavrenuek linked an issue Apr 21, 2026 that may be closed by this pull request
@n8n-assistant n8n-assistant Bot mentioned this pull request Apr 21, 2026
@n8n-assistant
Copy link
Copy Markdown
Contributor

n8n-assistant Bot commented Apr 21, 2026

Got released with n8n@2.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot run dev server with npm run dev in custom node project

2 participants