Symptoms
stencil startstops 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:
- 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.
- The token is no longer valid. BigCommerce says deleting an API account "invalidates its credentials", and deletion cannot be undone.
- 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.
- 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
- Look at the local config. Stencil V3.1 and later keep settings in two files.
config.stencil.jsonholds theme settings such as the store URL.secrets.stencil.jsonholds the access token. Older themes use a single.stencilfile. Back these files up before you change anything. Do not paste the token into logs, chat or issue reports. - Confirm the store URL. BigCommerce says the URL you give
stencil initshould 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. - 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.
- 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.
- Initialize again. Run
stencil init --url https://yourstore.com/ --token YOUR_TOKENfrom the theme folder. This rewrites the config with the new token. The "No api host found" warning itself suggests runningstencil initagain. One user in the issue thread already passed--apiHost https://api.bigcommerce.comtostencil initand still got the 401, and that flag is not listed in the BigCommerce options reference, so do not rely on it as the fix. - Fix CI separately. If it fails only in a pipeline, check that the job runs
stencil initwith 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. - 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) tostencil start. See the Stencil CLI options. - Verify the fix. Run
stencil startagain. 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.
Related problems to check
- Stencil still claims the CLI is outdated after an upgrade
- The store stops resolving after a custom domain change
Related articles
- Stencil still claims the CLI is outdated after an upgrade
- A custom Stencil web-page template does not appear
- A Stencil widget disappears on account URLs with query strings
- Logged-in shoppers cannot see prices in Cornerstone Quick Search
- A script added in Script Manager does not load
More in the BigCommerce knowledge base, including every article on Domains, themes and storefronts.