The directory .. doesn't have a package.json error when running npm run typegen

I created a new extension under our Shopify app by using this command:

npm run shopify app generate extension -- --template product_discounts --name product-discount

In the terminal, I moved inside the product-discount folder and run this command:

npm run typegen

The issue was it returned this error:

I am not sure why this is happening but I guarantee that package.json is inside the product-discount directory.

{
  "name": "product-discount",
  "version": "0.0.1",
  "license": "UNLICENSED",
  "scripts": {
    "shopify": "npm exec -- shopify",
    "typegen": "npm exec -- shopify app function typegen",
    "build": "npm exec -- shopify app function build",
    "preview": "npm exec -- shopify app function run",
    "test": "vitest"
  },
  "codegen": {
    "schema": "schema.graphql",
    "documents": "src/*.graphql",
    "generates": {
      "./generated/api.ts": {
        "plugins": [
          "typescript",
          "typescript-operations"
        ]
      }
    },
    "config": {
      "omitOperationSuffix": true
    }
  },
  "devDependencies": {
    "vitest": "^0.29.8"
  },
  "dependencies": {
    "@shopify/shopify_function": "0.1.0",
    "javy": "0.1.1"
  },
  "main": "index.js",
  "author": "",
  "description": ""
}

This is blocking me from updating the product-discount extension function.

Were you able to find a solution for this? I am facing the same issue

I’m also dealing with this issue and this seems to be the only place on the internet with this question. Can someone from shopify please take a look at this? I’m at a standstill on our storefront

It seems like the npm run shopify app function commands expects the parent directory of your extension directory to have a package.json.

The source code for these commands is in these files:

The source code for the “doesn’t have a package.json” is here:

There’s a ton of code, so I stopped reading, but I’m convinced the issue is somewhere in this app loader file:

It seems like the search for the project root only searches 2 directories max.

Best,

Tobe

Honestly, is anyone from shopify on these forums? 2 and a half months of silence.

I had the same issue running shopify app function typegen from within an extension. Realised it seems like the command needs to be ran from the root of the project, and then it offers you to select which extension you want to run it against. Hope this helps.