"Failed to fetch" error in story after generating JSON with Drush in container-less environment

Created on 19 September 2024, 5 months ago

Problem/Motivation

I was running in to an issue after following the "Drupal & Storybook in 5 Minutes" video and generating the .stories.json files using drush storybook:generate-stories.

I was met with the following error:

Upon reviewing my button.stories.json file I observed the following server URL:

"parameters": {
    "server": {
      "url": "http://default/storybook/stories/render"
    }
  },

Note: I am NOT using a container (docker, ddev, lando) for my local environment (my development environment is running directly on my local machine).

----

In my case the solution was to add:

export DRUSH_OPTIONS_URI="http://my-local-site-url.localhost"

to my ~/.bash-profile, delete the already generated .stories.json files, then re-run drush storybook:generate-stories. After that the generated JSON was corrected to:

"parameters": {
    "server": {
      "url": "http://my-local-site-url.localhost/storybook/stories/render"
    }
  },

and my stories began working as expected.

----

Additional note: I did reference a .lando.yml file to come to the conclusion as to what I needed. Here's the lando config i referenced where this environment variable is set:

tooling:
  drush:
    service: appserver
    env:
      DRUSH_OPTIONS_URI: "https://my-local-site-url.lndo.site/"

Proposed resolution

Looking at other related issues for this module it seems like others may be running in to the same issue where drush isn't using the correct URI when generating the stories JSON. I've never needed this environment variable set to work on a Drupal site prior to using this module so maybe something could be added to this module to account for that? Maybe fallback on the $baseurl if the environment variable is not set? Or perhaps document how to work around this scenario if not using a container, even just noting that DRUSH_OPTIONS_URI needs to be set?

📌 Task
Status

Active

Version

1.0

Component

Documentation

Created by

🇨🇦Canada tanner.svg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024