Skip to content

fix(core): Make n8n-workflow a peer dependency in ai-utilities#26404

Merged
DawidMyslak merged 3 commits intomasterfrom
node-4532-sdk-n8n-workflow-types-is-incompatible-with-peer-n8n
Mar 2, 2026
Merged

fix(core): Make n8n-workflow a peer dependency in ai-utilities#26404
DawidMyslak merged 3 commits intomasterfrom
node-4532-sdk-n8n-workflow-types-is-incompatible-with-peer-n8n

Conversation

@DawidMyslak
Copy link
Contributor

@DawidMyslak DawidMyslak commented Mar 2, 2026

Summary

When published to npm, @n8n/ai-utilities had n8n-workflow as a direct dependency, which allowed npm/pnpm to install a separate nested copy. Community nodes using @n8n/ai-node-sdk would then end up with two instances of n8n-workflow at runtime — one from the host (n8n) and one nested inside @n8n/ai-utilities — causing type mismatches and instanceof failures.

This PR moves n8n-workflow from dependencies to peerDependencies in @n8n/ai-utilities, so a single host-provided instance is used throughout.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-4532

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@DawidMyslak DawidMyslak marked this pull request as ready for review March 2, 2026 09:49
@DawidMyslak DawidMyslak requested a review from yehorkardash March 2, 2026 09:50
Copy link
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.

cubic analysis

No issues found across 3 files

Linked issue analysis

Linked issue: NODE-4532: SDK n8n-workflow types is incompatible with peer n8n-workflow

Status Acceptance criteria Notes
Move n8n-workflow from dependencies to peerDependencies in @n8n/ai-utilities Moved n8n-workflow out of dependencies into peerDependencies
Add n8n-workflow to peerDependencies in @n8n/ai-node-sdk Added peerDependencies entry for n8n-workflow
Update pnpm-lock.yaml to reflect peer dependency changes (avoid nested copy) pnpm-lock updated specifier/version to reflect change
⚠️ Ensure a single host-provided n8n-workflow instance is used at runtime (prevent type mismatches / instanceof failures) Peer deps added but no runtime/tests to verify single instance
Architecture diagram
sequenceDiagram
    participant Host as n8n (Host Process)
    participant Node as Community Node
    participant SDK as @n8n/ai-node-sdk
    participant Utils as @n8n/ai-utilities
    participant Workflow as n8n-workflow (Shared Instance)

    Note over Host,Workflow: Runtime Dependency Resolution

    Host->>Workflow: Load singleton instance
    Host->>Node: Load & Execute Node

    Node->>SDK: Call AI helper (e.g. supplyModel)
    
    SDK->>Workflow: CHANGED: Resolve peer dependency
    Note right of SDK: Uses Host's version of n8n-workflow
    
    SDK->>Utils: Forward request
    
    Utils->>Workflow: CHANGED: Resolve peer dependency
    Note right of Utils: No longer uses internal/nested copy
    
    alt Validation Path
        Utils->>Workflow: Perform instanceof check (ISupplyDataFunctions)
        Workflow-->>Utils: Match Found (Single Instance)
        Utils-->>SDK: Return initialized Model/Memory
        SDK-->>Node: Return data
    else Type Mismatch Path (Fixed)
        Note over Utils,Workflow: Previously: Instanceof would fail here <br/> due to nested n8n-workflow copies
        Utils-->>SDK: Error: Invalid type
    end

    Node-->>Host: Return node execution result
Loading

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Mar 2, 2026
"dependencies": {
"@n8n/ai-utilities": "workspace:*"
},
"peerDependencies": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need it here, if ai-utilities defines n8n-workflow dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, since community node templates already declare their own "n8n-workflow": "*" peer dependency independently, you're right - the SDK doesn't need to duplicate that.

…utilities

When published to npm, @n8n/ai-utilities had n8n-workflow as a direct
dependency, causing npm to install a separate nested copy. Community
nodes using @n8n/ai-node-sdk would then have two instances of
n8n-workflow — one from the host (n8n) and one nested inside
ai-utilities — leading to type mismatches and instanceof failures.

Move n8n-workflow to peerDependencies in both @n8n/ai-utilities and
@n8n/ai-node-sdk so a single host-provided instance is used throughout.

Made-with: Cursor
@DawidMyslak DawidMyslak force-pushed the node-4532-sdk-n8n-workflow-types-is-incompatible-with-peer-n8n branch from d056bce to 0a30eff Compare March 2, 2026 11:38
@DawidMyslak DawidMyslak changed the title fix(core): Make n8n-workflow a peer dependency in ai-node-sdk and ai-utilities fix(core): Make n8n-workflow a peer dependency in ai-utilities Mar 2, 2026
@DawidMyslak DawidMyslak requested a review from yehorkardash March 2, 2026 11:42
@DawidMyslak DawidMyslak enabled auto-merge March 2, 2026 11:48
@DawidMyslak DawidMyslak added this pull request to the merge queue Mar 2, 2026
Merged via the queue into master with commit b62d857 Mar 2, 2026
41 of 42 checks passed
@DawidMyslak DawidMyslak deleted the node-4532-sdk-n8n-workflow-types-is-incompatible-with-peer-n8n branch March 2, 2026 12:19
DawidMyslak added a commit that referenced this pull request Mar 2, 2026
@n8n-assistant n8n-assistant bot mentioned this pull request Mar 2, 2026
This was referenced Mar 3, 2026
@n8n-assistant
Copy link
Contributor

n8n-assistant bot commented Mar 3, 2026

Got released with [email protected]

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

Labels

n8n team Authored by the n8n team Released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants