Skip to content

[Bug]: Function build fails with 'Cannot convert undefined or null to object' - npm exec downloads wrong graphql-code-generator version #6745

@devdermo

Description

@devdermo

Describe the bug

When building Shopify Function extensions with @shopify/shopify_function@^2.0.0, the build fails with:

Cannot convert undefined or null to object
[10:16:12] Parse configuration [started]
[10:16:12] Parse configuration [failed]
[10:16:12] → Cannot convert undefined or null to object

Root Cause

The Shopify CLI runs npm exec -- graphql-code-generator --config package.json to generate GraphQL types. However, the graphql-code-generator binary from @graphql-codegen/cli (bundled in @shopify/shopify_function) is located in a nested path:

node_modules/@shopify/shopify_function/node_modules/.bin/graphql-code-generator

With npm workspaces, this binary is not hoisted to node_modules/.bin/. As a result, npm exec cannot find it locally and downloads [email protected] from npm registry (an ancient 2019 package with completely different config parsing).

The npm output shows:

npm warn exec The following package was not found and will be installed: [email protected]

To Reproduce

  1. Create a new Shopify app with function extensions using npm workspaces
  2. Run npm run dev or shopify app dev
  3. Observe the "Cannot convert undefined or null to object" error on all function builds

Expected Behavior

The build should use the @graphql-codegen/[email protected] bundled with @shopify/shopify_function, not download an incompatible ancient version.

Workaround

Add the graphql-codegen packages as direct dependencies in the root package.json:

{
  "dependencies": {
    "@graphql-codegen/cli": "5.0.5",
    "@graphql-codegen/typescript": "4.1.6",
    "@graphql-codegen/typescript-operations": "4.6.0"
  }
}

This exposes the binary at node_modules/.bin/graphql-code-generator so npm exec finds it locally.

Suggested Fix

Either:

  1. Add these packages as peer dependencies in @shopify/shopify_function so they're hoisted
  2. Change the CLI to use the full path to the binary within @shopify/shopify_function
  3. Use npx --package=@graphql-codegen/cli graphql-codegen instead of npm exec -- graphql-code-generator

Environment

  • Shopify CLI version: 3.88.1
  • Node.js version: 24.12.0
  • npm version: 11.6.2
  • Operating System: macOS (Darwin 25.2.0)
  • @shopify/shopify_function version: ^2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions