Typeerror: scopesArray.map is not a function when using postgresql

Topic summary

TypeError occurs after switching session storage from SQLite to PostgreSQL with @shopify/shopify-app-session-storage-postgresql; the app crashes at the middleware shopify.validateAuthenticatedSession() with “scopesArray.map is not a function,” originating in the Shopify API scopes handler.

Key context:

  • Session data is successfully saved to PostgreSQL before the crash.
  • validateAuthenticatedSession is a middleware requiring an active session; “scopes” are OAuth permission strings.
  • Another developer reports the same error (screenshot shared).

Identified cause:

  • Installing @shopify/shopify-app-session-storage-postgresql in the project’s top-level package.json (instead of the /web app directory) creates duplicate @shopify/shopify-api instances in the monorepo/template setup, leading to a type mismatch for scopesArray.

Resolution/action:

  • Move @shopify/shopify-app-session-storage-postgresql dependency to /web/package.json and run npm install; remove top-level installation to ensure a single @shopify/shopify-api instance.
  • Reference: linked GitHub issue confirms the fix.

Status: Resolved by adjusting dependency location; no further open questions reported.

Summarized with AI on January 31. AI used: gpt-5.

I’m creating an Shopify app using Node with SQLite it’s working fine on local and also when deploy on Heroku too.

but now I’m going to use PostgreSQL instead of SQLite as you know Heroku reset SQLite on each deployment so i decide to use PostgreSQL for production so i successfully setup using

@shopify/shopify-app-session-storage-postgresql

session details are successfully stored in database but application crashed when reached at

// All endpoints after this point will require an active session
app.use("/api/*", shopify.validateAuthenticatedSession());

for validation and show error

/node_modules/@shopify/shopify-api/lib/auth/scopes/index.js:15
 .map(function (scope) { return scope.trim(); })

TypeError: scopesArray.map is not a function

node_modules/@shopify/shopify-app-express/build/cjs/middlewares/validate-authenticated-session.js:57:79

Please guide me how can i shift from SQLite to PostgreSQL or it’s somethings wrong from my side.

1 Like

Same error

This is happening because you are installing the** @Shopify_77 /shopify-app-session-storage-postgresqlpackage in the top directory and not in the /web directory. This is causing a conflict with having duplicate @Shopify_77 /shopify-api**instances.

Moving this from top level package.json to the /web package.json and npm install should fix this. Found the solution here - https://github.com/Shopify/shopify-app-template-node/issues/1208

1 Like