Skip to content

TypeError: Cannot read properties of undefined (reading 'token') on auth pages (e.g. /login.php) #1364

@SamuelCook

Description

@SamuelCook

Description

Navigating to any auth page (e.g. /login.php) while running stencil start
results in a 500 error. The local server crashes with:

  TypeError: Cannot read properties of undefined (reading 'token')
      at internals.parseResponse (server/plugins/renderer/renderer.module.js:222:81)

Root Cause

In parseResponse, the CLI unconditionally reads settings.storefront_api.token
to fetch Page Builder regions via GraphQL:

  if (pageType) {
      regionResponse = await contentApiClient.getRenderedRegionsByPageType({
          accessToken: response2.data.context.settings.storefront_api.token,
          ...
      });
  }

BigCommerce does not include storefront_api in the page context for auth pages
(login, create account, forgot password, etc.). This makes storefront_api
undefined, and the .token access throws.

Steps to Reproduce

  1. Run stencil start against any store
  2. Navigate to http://localhost:3000/login.php
  3. Observe 500 response and the TypeError in the terminal

Expected Behaviour

Auth pages render normally. They contain no Page Builder regions requiring a
Storefront API token, so the GraphQL fetch should be skipped or handled gracefully.

Suggested Fix

Guard before the fetch:

  if (pageType && response2.data.context.settings.storefront_api) {

Or use optional chaining:

  accessToken: response2.data.context.settings.storefront_api?.token,

Environment

  • @bigcommerce/stencil-cli: 9.0.1 (also present in 9.0.0)
  • Node.js: v24.14.1
  • OS: macOS
  • Affected pages: /login.php and any auth page where BigCommerce omits
    storefront_api from the context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions