Skip to content

OpenRPC Generator Runtime Error - Cannot read properties of undefined (affects v2.1.0, v1.22.3, v1.18.13, v1.15.5) #736

Description

@seanzhou321

Bug Report: OpenRPC Generator Runtime Error - "Cannot read properties of undefined"

Summary

The OpenRPC generator fails with a runtime TypeError when attempting to generate clients from valid OpenRPC schemas. This affects multiple versions across both 1.x and 2.x release lines, making the tool effectively unusable.

Environment

  • OS: Windows 11
  • Node.js: Latest (via npx)
  • Generator Versions Tested:
    • @open-rpc/generator@2.1.0 (latest)
    • @open-rpc/generator@1.22.3
    • @open-rpc/generator@1.18.13
    • @open-rpc/generator@1.15.5

Error Details

Primary Error (v2.1.0)

TypeError: Cannot read properties of undefined (reading 'hooks')
    at getComponentFromConfig (C:\Users\xyz\AppData\Roaming\npm\node_modules\@open-rpc\generator\build\index.js:82:32)
    at exports.default (C:\Users\xyz\AppData\Roaming\npm\node_modules\@open-rpc\generator\build\index.js:175:33)
    at async Command.<anonymous> (C:\Users\xyz\AppData\Roaming\npm\node_modules\@open-rpc\generator\build\index.js:188:9)

Secondary Error (v1.22.3, v1.18.13, v1.15.5)

TypeError: Cannot read properties of undefined (reading 'beforeCopyStatic')
    at copyStaticForComponent (...)

Reproduction Steps

Method 1: Command Line Generation

# Create a minimal valid OpenRPC schema
npx @open-rpc/generator generate -d ./schema.json -o ./output -l go

Method 2: Using Init + Config

# This works and creates config
npx @open-rpc/generator init

# But this fails with the error
npx @open-rpc/generator generate -c ./open-rpc-generator-config.json

Minimal Test Schema

The error occurs even with a minimal, valid OpenRPC 1.3.2 schema:

{
  "openrpc": "1.3.2",
  "info": {
    "title": "Test API",
    "version": "1.0.0",
    "description": "Minimal test schema"
  },
  "methods": [
    {
      "name": "test_method",
      "summary": "Test method",
      "params": [
        {
          "name": "param1",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "result": {
        "name": "TestResult",
        "schema": {
          "type": "object",
          "properties": {
            "message": {
              "type": "string"
            }
          }
        }
      }
    }
  ]
}

Commands That Fail

All of these commands produce the runtime error:

# Latest version
npx @open-rpc/generator@2.1.0 generate -d ./schema.json -o ./output -l go

# Previous stable versions
npx @open-rpc/generator@1.22.3 generate -d ./schema.json -o ./output -l go
npx @open-rpc/generator@1.18.13 generate -d ./schema.json -o ./output -l go
npx @open-rpc/generator@1.15.5 generate -d ./schema.json -o ./output -l go

Expected Behavior

The generator should:

  1. Parse the OpenRPC schema successfully
  2. Generate the requested client code in the specified language
  3. Output the generated files to the specified directory

Actual Behavior

The generator:

  1. Starts processing the schema
  2. Crashes with a TypeError about undefined properties
  3. Exits with code 1, generating no output

Impact

This bug makes the OpenRPC generator completely unusable for:

  • Generating Go clients (tested language)
  • Any client generation workflows
  • Integration with build systems and CI/CD pipelines

The error suggests the issue is in the component loading/configuration system, affecting the core functionality regardless of schema validity.

Additional Context

  • The npx @open-rpc/generator init command works correctly and creates valid config files
  • The --help and --version commands work correctly
  • The error occurs immediately during generation, suggesting it's not schema-specific
  • Multiple users may be affected as this spans several versions
  • This prevents adoption of OpenRPC in projects that require reliable code generation

Suggested Investigation

The error patterns suggest:

  1. v2.1.0: Issue with hooks property access in getComponentFromConfig
  2. v1.x: Issue with beforeCopyStatic property access in copyStaticForComponent

This might indicate:

  • Missing or incorrectly initialized component configuration objects
  • Breaking changes in dependency management between versions
  • Issues with the component loading system

Would appreciate any guidance on workarounds or timeline for a fix, as this blocks OpenRPC adoption in projects requiring reliable client generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions