Navigating the 'graphql-code-generator not found' Error in Shopify CLI 4.8.0
Hey everyone! As a Shopify migration expert and someone who loves digging into the community forums, I often see common headaches pop up for our amazing store owners and developers. Recently, a specific issue caught my eye, and it's one that many of you building custom Shopify apps and extensions might run into: the dreaded "graphql-code-generator not found" error when trying to generate a discount extension with Shopify CLI 4.8.0. It's a tricky one, but thanks to some brilliant minds in the community, we've got a few solid paths to resolution.
This whole discussion kicked off with Renzo_Gil_Cruzado, who was trying to get a simple JavaScript discount function off the ground. They hit a wall right after running shopify app generate extension --template discount, getting an error that screamed ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Command "graphql-code-generator" not found. Sound familiar? You're not alone!
Unpacking the Root Cause: Why is This Happening?
It turns out this isn't just a simple "forgot to install a package" problem. The community, especially v.marychenka and Josh-FiveAcreCode, helped shine a light on the underlying mechanics. Here's the gist:
- The Sneaky
pnpm-workspace.yaml: Even if you initialize your Shopify app withnpm, the extension-only template might leave apnpm-workspace.yamlfile behind. Shopify CLI 4.8.0, in its wisdom, checks for this file beforepackage-lock.json. This means it might default to usingpnpminternally for generating the extension, even if you specifiednpm. - Transitive Dependency Trouble: The
graphql-code-generatorisn't a direct dependency of your app. It comes in via@shopify/shopify_function. Whenpnpmis used with its default "isolated" linking strategy, it doesn't always link these transitive dependencies wherepnpm execexpects to find them. This makes the binary "unresolvable" at the workspace level. - A CLI Regression: Josh-FiveAcreCode pointed out that this might even be a regression in the Shopify CLI itself, as similar failures have been reported across npm, pnpm, and yarn, and across different CLI versions since 2023.
Your Toolkit for Fixing the 'graphql-code-generator not found' Error
Thankfully, the community came through with several actionable solutions. Let's walk through them.
Solution 1: The Cleanup and Reinstall (v.marychenka's Approach)
This is your first line of defense, especially if you suspect a lingering pnpm configuration is the culprit. It ensures a clean slate for npm to take over.
- Move any hand-written extension folders: If you've tried to manually create extension folders, move them out of your
extensions/directory temporarily to avoid conflicts. - Clean up existing package manager files: From your app's root directory, run the following command to remove old module installations and pnpm-specific files:
- Reinstall dependencies with npm:
- Try generating the extension again:
rm -rf node_modules pnpm-lock.yaml pnpm-workspace.yaml
npm install
shopify app generate extension --template discount --name volume-discount
Solution 2: Directly Install Codegen Dependencies (Josh-FiveAcreCode's Workaround)
If the cleanup doesn't work, or if you're experiencing the issue even without the pnpm-workspace.yaml interference, directly installing the necessary GraphQL Code Generator packages at your app's root can resolve the binary resolution problem.
- Install the packages: Depending on your package manager, run one of these commands from your app's root:
- With npm:
npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations - With pnpm:
pnpm add -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations - Attempt extension generation again:
shopify app generate extension --template discount --name volume-discount
Solution 3: Advanced pnpm Configuration for Stubborn Cases (VikashJ's Insight)
If you're consistently using pnpm and the direct install still isn't cutting it, VikashJ from Apploy suggested a deeper dive into pnpm's linking strategy. The default "isolated" linking can be the exact reason why a workspace-installed binary isn't found. Switching to "hoisted" can often fix this class of "package installed but binary not found" issues.
- Create or modify your
.npmrcfile: At your app's root, create a file named.npmrc(if it doesn't exist) or add the following line to it: - Reinstall dependencies: After modifying
.npmrc, you'll need to reinstall your dependencies for the change to take effect. - Try generating the extension:
node-linker=hoisted
shopify app generate extension --template discount --name volume-discount
Tackling the 'Invalid Extension Configuration' for JS Functions
Renzo also ran into another frustrating roadblock: after giving up on generate extension and hand-writing the extension folder, they hit an "Invalid extension configuration" error. This is crucial for anyone building JavaScript functions!
Josh-FiveAcreCode clarified a common misconception here: for JavaScript Functions, the Shopify CLI handles the JS-to-Wasm build itself. You should not set command = "shopify app function build" in your shopify.extension.toml.
The correct configuration for a JavaScript discount function should look something like this:
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"
Notice the command = "" under [extensions.build]. This tells the CLI to manage the build process for your JavaScript function, outputting to dist/function.wasm.
A Call to Action: Report Those Bugs!
Finally, a critical point from VikashJ: if you've consistently reproduced these issues, especially with specific CLI and Node versions (like 4.8.0 and 24.14.0 in this case), please consider filing a new, tightly-scoped bug report. A well-documented reproduction with exact versions is incredibly valuable to the Shopify engineering team and gets triaged much faster than a general community thread. This helps everyone in the long run!
It's clear that developing on the bleeding edge of any platform can come with its quirks, and Shopify development is no exception. But the strength of our community in troubleshooting and sharing solutions is truly remarkable. Keep at it, and don't hesitate to lean on these insights when you hit your next development snag!