Cracking the 'graphql-code-generator' Error: Shopify CLI 4.8.0 Discount Extension Fix

Hey everyone,

It’s always a bit frustrating when you’re building something cool for your Shopify store and hit a wall with the tooling, right? Especially when the error message isn’t immediately clear. Recently, our community had a good discussion around a specific hiccup many developers encountered with Shopify CLI 4.8.0: the dreaded message graphql-code-generator not found when trying to generate discount extensions.

This wasn't just a one-off issue; it popped up for multiple folks using either npm or pnpm. It’s a classic case of a transitive dependency not being where the CLI expects it, leading to a frustrating roadblock. Let's break down what was happening and, more importantly, how our community experts helped crack it.

Understanding the 'graphql-code-generator not found' Error

The original poster, Renzo_Gil_Cruzado, detailed the problem: running shopify app generate extension --template discount --name volume-discount would error out with Command "graphql-code-generator" not found. This occurred even after initializing the app with npm.

The core of the issue, as diagnosed by v.marychenka, was clever. The extension-only app template was leaving a pnpm-workspace.yaml file at the app root. Even if you specified init --package-manager npm, CLI 4.8.0 would check for pnpm-workspace.yaml *before* package-lock.json, defaulting to pnpm internally for extension generation.

The kicker: graphql-code-generator isn't a direct dependency; it comes via @shopify/shopify_function. Because pnpm uses an "isolated" linking strategy by default, it wasn't linking graphql-code-generator where pnpm exec could easily find it when the CLI tried to run it.

:waving_hand:

Community-Tested Solutions & Workarounds

Our community jumped in with several effective strategies. Here’s a synthesis of the best approaches:

1. The Clean Slate Approach (v.marychenka)

Sometimes, a good old-fashioned cleanup resolves package manager confusion. If you've been experimenting or hitting this issue, start fresh with your dependencies:

  1. Move custom code: Temporarily move any custom folders *out* of the extensions/ directory.
  2. Clean up old files: From your app root, run these commands:
    rm -rf node_modules pnpm-lock.yaml pnpm-workspace.yaml

    Don't skip node_modules! Running npm install on a pnpm-made node_modules can cause further issues.

  3. Reinstall dependencies:
    npm install
  4. Generate your extension again:
    shopify app generate extension --template discount --name volume-discount

2. Directly Installing Codegen Dependencies (Josh-FiveAcreCode)

Josh suggested this might be a Shopify CLI regression, and a common workaround is to explicitly install the necessary GraphQL Code Generator packages directly at your app's root. This ensures they are easily resolvable.

To implement this:

  1. From your app root, run one of the following commands:

    If using pnpm:

    pnpm add -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations

    If using npm:

    npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations
  2. After installing, try generating your extension again:
    shopify app generate extension --template discount --name volume-discount

3. Adjusting pnpm's Node Linker (VikashJ)

For stubborn cases with pnpm, VikashJ offered another troubleshooting step. pnpm's default "isolated" node-linker setting can sometimes prevent binaries from being resolved when tools shell out from different working directories.

To try this:

  1. In your app root, create or modify a .npmrc file.
  2. Add the following line:
    node-linker=hoisted
  3. Remove node_modules and pnpm-lock.yaml.
  4. Reinstall dependencies (e.g., pnpm install).
  5. Then, try generating your extension.

Correcting Your Shopify Function Configuration (shopify.extension.toml)

Renzo’s follow-up highlighted another common pitfall: configuring shopify.extension.toml for JavaScript functions. He initially faced "doesn't have a build command" then "Invalid extension configuration."

Josh provided the crucial insight: for a JavaScript Function, the Shopify CLI handles the JS-to-Wasm build itself. You should not set command = "shopify app function build". This can point the build process back at itself.

The correct configuration for a JavaScript discount function's [extensions.build] section should be:

[extensions.build]
command = ""
path = "dist/function.wasm"

This tells the CLI to manage the build and expect output at dist/function.wasm. Josh shared a full, working example of a JS discount Function config:

api_version = "2026-01"

[[extensions]]
name = "t:name"
handle = "volume-discount"
type = "function"
description = "t:description"

[[extensions.targeting]]
target = "cart.lines.discounts.generate.run"
input_query = "src/cart_lines_discounts_generate_run.graphql"
export = "cart-lines-discounts-generate-run"

[[extensions.targeting]]
target = "cart.delivery-options.discounts.generate.run"
input_query = "src/cart_delivery_options_discounts_generate_run.graphql"
export = "cart-delivery-options-discounts-generate-run"

[extensions.build]
command = ""
path = "dist/function.wasm"

Also, v.marychenka reminded us that for the CLI to treat your function as JavaScript, it specifically looks for src/index.js or src/index.ts. If you're hand-writing, ensure your entry point matches this.

What to Do if You're Still Stuck: Reporting Bugs

If these workarounds don't solve your issue, especially with CLI 4.8.0 or Node 24.14.0, file a new, tightly-scoped bug report with Shopify. As VikashJ wisely noted, a well-documented reproduction with exact versions is triaged fastest. The original thread mentioned related open issues, so adding your detailed repro steps can genuinely help the Shopify team resolve these regressions.

It's awesome to see the community come together to debug and share solutions like this. App development always has its quirks, but with collective knowledge, we can usually navigate them. Keep building those amazing Shopify apps!

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools