bigcommerce / stencil-cli

BigCommerce Stencil emulator for local theme development
https://developer.bigcommerce.com/stencil-docs
BSD 4-Clause "Original" or "Old" License
102 stars 142 forks source link

No API host found in config file #1047

Open BC-AdamWard opened 1 year ago

BC-AdamWard commented 1 year ago

No api host found in config file, falling back to https://api.bigcommerce.com/. You may need to run 'stencil init' again.

Looks very similar to https://github.com/bigcommerce/stencil-cli/issues/844

Running stencil init -h https://api.bigcommerce.com/solved for me.

Expected behavior

Stencil start throws no errors

Actual behavior

After running Stencil Start we receive a message of:

No api host found in config file, falling back to https://api.bigcommerce.com/. You may need to run 'stencil init' again.

Running Stencil init again does not resolve the issue

Steps to reproduce behavior

Environment

Stencil-cli version stencil --version: 6.0.0

Node version node -v: 14.20.0

NPM version npm -v:6.14.17

OS: MacS Monterey version 12.6

jairo-bc commented 1 year ago

Hi @BC-AdamWard, do yo mind to provide screenshots for the errors you had?

BC-AdamWard commented 1 year ago

Hey Jairo,

Error on Stencil Start -

image

It does still launch but after that it seems some updates to the theme files do not get reflected in Browsersync appropriately.

The error also pops up on stencil push, but the file seems to be pushed correctly

image

Running stencil init also receives the error. image

However, even though Stencil Init says it is adding the host, it is not saved in my config.stencil.json file unless I explicitely run stencil init -h https://api.bigcommerce.com

image

Let me know if I can help with anything else. The biggest issue was not seeing changes reflected on localhost.

jairo-bc commented 1 year ago

Hi @BC-AdamWard, I don't see any errors, on the screenshots you provided. 'No Api host' message is just a warning to be aware of what is in your config

OloorinOfTheSouth commented 1 year ago

I've had exactly the same issue as @BC-AdamWard. Am In the middle of doing a manual upgrade to Cornerstone 6.7 (from 1.3, don't ask), tried doing a test with a fresh install, get to the exact same point. Here's the error that it throws back:

not ok -- StoreSettingsLocaleError: Request failed with status code 403

URL: https://api.bigcommerce.com/stores/9x14icgu4u/v3/settings/store/locale Method: GET

Incidentally, tried using @BC-AdamWard's approach and firing stencil init -h https://api.bigcommerce.com/ but that would just throw back this error:

not ok -- Error: Could not fetch a list of the store channels: Request failed with status code 404

Been using Stencil/Cornerstone for my custom Bigcommerce page for a few years now, also the first time I've noticed this after I run stencil init:

Set API host to: https://api.bigcommerce.com/ You are now ready to go! To start developing, run $ stencil start

I've never seen it ask for the API host to be set, is that new, would that normally print out?

OloorinOfTheSouth commented 1 year ago

Just to quickly update, I just tried running stencil start, just to see what would happen, haven't done anything or made any changes at all, haven't touched a single thing since the last post (given it's been NYE and all), and now Stencil miraculously starts up, but still with a No api host found warning injected in the first line. Screenshot 2023-01-01 at 2 23 01 am

So I can get past the API error for now it seems, but once I've booted Stencil up it looks like I have no dist folder generating. Great. I swear, just getting this environment up and running has been the biggest pain in the ass.

LoveSpirals commented 1 year ago

I encountered this also, and was able to resolve it by recreating the API account. That is, as the site owner: Settings -> Api Accounts -> Create new Api Account Then create one using of type "Stencil CLI account".

Using the resulting values, rerun stencil init, e.g.: stencil init --url https://yourdomainy.com --token yourtoken

More info: I ran into this when trying to run stencil start locally on Windows 10. Our BigCommerce theme hadn't been updated for about a year.

JinMengmeng1998 commented 1 year ago

Hello, have you solved this problem? I also had this problem and recreated the token, which was also not resolved.

LoveSpirals commented 1 year ago

Hello, have you solved this problem? I also had this problem and recreated the token, which was also not resolved.

Yes, I recreated the API account and then re-ran stencil init. That's all I know. :|

JinMengmeng1998 commented 1 year ago
GearUp2Go commented 1 year ago

This is what I had to do. I think there's a scope issue with Stencil CLI tokens. When you're creating a new token, create a V2/V3 API token with the following scopes set:

n3k027 commented 7 months ago

I was able to resolve the "No Api host" issue with the following command stencil init -h https://api.bigcommerce.com it added "apiHost": "https://api.bigcommerce.com" to the config.stencil.json

{
  "customLayouts": {
    "brand": {},
    "category": {},
    "page": {},
    "product": {}
  },
  "normalStoreUrl": "https://[YOUR_STORE_URL].mybigcommerce.com/",
  "port": 3000,
  "apiHost": "https://api.bigcommerce.com"
}