BigCommerce Troubleshooting

Stencil start fails with 401 while fetching store channels

Stencil start fails with a 401 fetching store channels; fix it by re-running stencil init with a valid Stencil-CLI token from the same store as the configured URL.

Last updated · Domains, themes and storefronts · Error code: 401 · Applies to: Stencil CLI (stencil start) on BigCommerce Stencil themes, local and CI

Symptoms

  • stencil start stops before the local preview opens and prints: "not ok -- Error: Could not fetch a list of the store channels: Request failed with status code 401".
  • You may also see this warning just before it: "No api host found in config file, falling back to https://api.bigcommerce.com. You may need to run 'stencil init' again."
  • Other Stencil commands can return 401 as well. One user in the public issue reported that every Stencil command failed this way.
  • It can work on your machine but fail in a CI job such as GitHub Actions, or the reverse.

Cause

stencil start asks the store for its list of storefront channels before it serves the preview, and that request uses the token saved by stencil init. A 401 means the store rejected that token. The common reasons, most likely first:

  1. The token belongs to a different store than the URL in your config. This often happens after you copy a theme folder between projects or switch between a sandbox and a production store.
  2. The token is no longer valid. BigCommerce says deleting an API account "invalidates its credentials", and deletion cannot be undone.
  3. The token is the wrong kind. BigCommerce's local preview docs tell you to create a Stencil-CLI token. When you create a store-level API account, the token type is chosen separately from a V2/V3 API token.
  4. The token is not supplied where the command runs. A CI job does not see your local config files, so it has to run stencil init (or otherwise provide the token) from a stored secret on every run.

The public Stencil CLI issue #1090 shows this error, including cases that worked locally and failed only in CI. That thread never confirmed one root cause, so work through the checks below in order.

Resolution

  1. Look at the local config. Stencil V3.1 and later keep settings in two files. config.stencil.json holds theme settings such as the store URL. secrets.stencil.json holds the access token. Older themes use a single .stencil file. Back these files up before you change anything. Do not paste the token into logs, chat or issue reports.
  2. Confirm the store URL. BigCommerce says the URL you give stencil init should be the store's vanity URL. Make sure it is the store you expect, not an old sandbox or a domain you have moved away from.
  3. Check that the token still exists. In the control panel, go to Settings › Store-level API accounts on the same store. If you cannot find the account that issued the token, it was likely deleted. You need the List, Create and Delete store-level API Accounts permissions to manage these.
  4. Create a fresh Stencil-CLI token if needed. Click Create API Account and choose the Stencil-CLI token type. The local preview docs list two access levels, "local development only" and "publish theme". Use the lower one unless you also push themes. A store can hold at most 50 store-level API accounts, so delete unused ones first if you hit that limit.
  5. Initialize again. Run stencil init --url https://yourstore.com/ --token YOUR_TOKEN from the theme folder. This rewrites the config with the new token. The "No api host found" warning itself suggests running stencil init again. One user in the issue thread already passed --apiHost https://api.bigcommerce.com to stencil init and still got the 401, and that flag is not listed in the BigCommerce options reference, so do not rely on it as the fix.
  6. Fix CI separately. If it fails only in a pipeline, check that the job runs stencil init with the store URL and token from stored secrets before any other Stencil command, and that the secret holds the current token for the right store. A secret that still holds a deleted or replaced token produces the same 401.
  7. Pick the channel explicitly on multi-storefront stores. If your store has more than one storefront, choose the channel when prompted, or pass --channelId (-c) or --channelUrl (-cu) to stencil start. See the Stencil CLI options.
  8. Verify the fix. Run stencil start again. The channel list should load, the preview should open on your local port, and pages should show the storefront you picked.

If a new token for the right store still returns 401, contact BigCommerce support. Send your Stencil CLI version, Node.js version, the exact error line and the store URL, but never the token.

How to prevent it

  • Keep one theme folder per store, or keep separate config files for sandbox and production.
  • Name Stencil API accounts clearly so no one deletes them during a cleanup.
  • Store CI tokens as pipeline secrets and update them whenever you replace a token.
  • Match your Node.js version to what your Stencil CLI release supports. A reply in the issue thread asked about supported Node.js and npm versions for this error.

B2B and multi-storefront notes

B2B stores often run separate storefronts for trade and retail buyers, so the channel step in step 7 matters more than usual. Confirm you are previewing the intended channel before you judge how the theme behaves.

Stencil tokens are separate from the API accounts your ERP connector or other integrations use. Creating or deleting a Stencil token does not affect them, but deleting the wrong account during cleanup can. If an integration starts failing with 401 at the same time, see The REST Admin API returns 401 or 403.

More in the BigCommerce knowledge base, including every article on Domains, themes and storefronts.