: [shopify-app-express] Error: ensureInstalledOnShop did not receive a shop query argument

Hi everyone,

I’m encountering an error with

@shopify/shopify-app-express

(v5.0.8) in my Node.js app. My server is crashing/logging an error when

ensureInstalledOnShop()

is called.

The Error:

[shopify-app/ERROR] ensureInstalledOnShop did not receive a shop query argument | {shop: undefined}

This happens in my

index.jsmiddleware setup where I’m handling frontend rendering. It seems like the request reaching this middleware is missing the

shop

query parameter, even though I’m expecting Shopify to pass it.

Code Snippet (

web/index.js):

javascript

app.use(“*”, async (req, res, next) => {

// Skip Shopify install check for API routes

if (req.path.startsWith(“/api”)) {

return next();

}

// Only allow GET requests for frontend rendering

if (req.method !== “GET”) {

return next();

}

// Error occurs here

return shopify.ensureInstalledOnShop()(req, res, async () => {

return res

.status(200)

.set(“Content-Type”, “text/html”)

.send(

readFileSync(join(STATIC_PATH, “index.html”))

.toString()

.replace(“%VITE_SHOPIFY_API_KEY%”, process.env.SHOPIFY_API_KEY || “”)

  );

});

});

Steps to Reproduce:

  1. Run

    npm run dev
    
  2. App starts successfully.

  3. The error appears in the terminal when I try to open the app (or when a restart happens).

Has anyone faced this issue where the

shop

argument is undefined at this stage? Any advice on how to handle cases where the query param might be missing?

Thanks in advance!

@snsd ,

ensureInstalledOnShop() requires ?shop= in the URL.
When your * route runs without it, shop is undefined, so the app crashes.

Fix: guard before calling it.

app.use("*", (req, res, next) => {
  if (req.path.startsWith("/api")) return next();
  if (req.method !== "GET") return next();

  if (!req.query.shop) {
    return res.redirect("/api/auth");
  }

  return shopify.ensureInstalledOnShop()(req, res, next);
});

thanks we solved it we did unccery changes in tempalte now fixed