Storybook: Build Storybook iframe.html Failed to load resource

Created on 27 Jul 2020  路  12Comments  路  Source: storybookjs/storybook

Hi,

When build storybook is executed, output is executed or distributed.
However, it failed to load resoure despite the bundle file in iframe.html.
Of course, you can change the path to absolute path directly in iframe.html, but do you have to do this every time?

Version
"@storybook/addon-docs": "^5.3.19",
"@storybook/cli": "^5.3.19",

To Reproduce
Steps to reproduce the behavior:

  1. build storybook
  2. output storybook-static
  3. load to index.html
  4. See error

Screenshots
If applicable, add screenshots to help explain your problem.

Screen Shot 2020-07-27 at 11 44 46 AM

The path is wrong, as in the code below.

Screen Shot 2020-07-27 at 2 38 18 PM

build-storybook question / support tracked

All 12 comments

We had this issue so I've managed to fix this by running shell script in postbuild step in PR.

Do you have an example?

When I build storybook, and host it: npx http-server ./static-storybook it works!

We can't hard-code an absolute url, because some people host static-storybook in a sub-directory.

@ndelangen Thanks for the response,
code is in the repository below.
https://github.com/dooboolab/dooboo-ui/tree/master/doc
We deploy gh-page branch after build.

So you change:

<script src="runtime~app.1491145c4d6866f9125d.bundle.js"></script>

into:

<script src="/runtime~app.1491145c4d6866f9125d.bundle.js"></script>

Why are your assets and html pages not in the same directory when deploying?

Why would this 'hack' not be needed for index.html, but it is for iframe.html?

package.json script

yarn build

build result
釀夅叧釀忈叧釀呩叺釂剦釁a喓 2020-07-28 釀嬦叐釀掅叜 9 07 51

incorrect

<script src="/runtime~app.1491145c4d6866f9125d.bundle.js"></script>

When I create a build storybook

Deploy the files in the storybook-static folder to git-pages.

The build result index.html, iframe.html and iframe.html are created. When I open the iframe.html file, the output of the bundle.js file is incorrect and it outputs

@s-ong-c I'm having difficulty understanding what you mean.

Can you tell me if this statement is correct?
https://github.com/storybookjs/storybook/issues/11694#issuecomment-664975697

When I look at https://dooboolab.github.io/dooboo-ui/iframe.html

I observe:
Screenshot 2020-07-29 at 11 30 47

So are you removing the / slashes rather then adding them?

@ndelangen
Sorry for not giving a good explanation

first
in the doc directory
Screen Shot 2020-07-29 at 6 53 04 PM

build
Screen Shot 2020-07-29 at 6 53 24 PM

Screen Shot 2020-07-29 at 6 53 43 PM

build result static-storybook directory
Screen Shot 2020-07-29 at 6 54 32 PM

Screen Shot 2020-07-29 at 6 54 21 PM

Screen Shot 2020-07-29 at 6 55 04 PM

Screen Shot 2020-07-29 at 6 55 00 PM

The src path in Iframe.html is wrong as below.
Screen Shot 2020-07-29 at 6 55 41 PM

Screen Shot 2020-07-29 at 6 56 50 PM

but The src path in index.html is correct as below.
Screen Shot 2020-07-29 at 7 52 00 PM

Screen Shot 2020-07-29 at 6 56 39 PM

So are you removing the / slashes rather then adding them? YES

But should I do this every time??

That does sound like a bug..

Would you be open to trying the 6.0.0 RC? I think it's fixed in that. If you really need a patch on 5.x, could you assist?
We could schedule a meeting so I could help you get setup:
https://calendly.com/ndelangen/storybook

Try upgrading to 6.0 RC?

npx sb@next upgrade --prerelease

Try upgrading to 6.0 RC?

npx sb@next upgrade --prerelease

I tried to upgrade, but the same error
so https://calendly.com/ndelangen/storybook schedule a meeting was booked.

Not sure what the fix would be, since I don't know anything about Expo, but I took a look and see what is happening, if that hadn't been found. Not sure if the problem was just about a fix or why it is happening, because the cause seems intentional, for some reason that may make sense if you know about expo.

The withUnimodules function that is wrapping the config in .storybook/webpack.config.js makes sure webpackConfig.output.publicPath resolves from the root. Seems like a strict assumption, but since I don't know anything about Expo, maybe it makes sense for those projects.

Only affects iframe.html, because index.html is built from Storybook's manager webpack-config, but Storybook's preview webpack-config scripts use .storybook/webpack.config.js, not manager.

Instead of a postbuild shell script, I did the following, to reset output.publicPath back to '':

// .storybook/webpack.config.js
...

module.exports = ({ config, mode }) => {
  ...

  const wUni = withUnimodules(config, {
    projectRoot: resolve(__dirname, '../'),
    // babel: {
    //   dangerouslyAddModulePathsToTranspile: [
    //     // Ensure that all packages starting with @evanbacon are transpiled.
    //     'dooboo-ui',
    //   ],
    // },
  });
  wUni.output.publicPath = ''
  return wUni
};

Following withUnimodules source for anything that would affect output.publicPath lead to https://github.com/expo/expo-cli/blob/ca0c33e353887da7593a8ce4fa7ad5ef654845b6/packages/webpack-config/src/env/paths.ts#L156, which describes what its doing.

Not sure what the fix would be, since I don't know anything about Expo, but I took a look and see what is happening, if that hadn't been found. Not sure if the problem was just about a fix or why it is happening, because the cause seems intentional, for some reason that may make sense if you know about expo.

The withUnimodules function that is wrapping the config in .storybook/webpack.config.js makes sure webpackConfig.output.publicPath resolves from the root. Seems like a strict assumption, but since I don't know anything about Expo, maybe it makes sense for those projects.

Only affects iframe.html, because index.html is built from Storybook's manager webpack-config, but Storybook's preview webpack-config scripts use .storybook/webpack.config.js, not manager.

Instead of a postbuild shell script, I did the following, to reset output.publicPath back to '':

// .storybook/webpack.config.js
...

module.exports = ({ config, mode }) => {
  ...

  const wUni = withUnimodules(config, {
    projectRoot: resolve(__dirname, '../'),
    // babel: {
    //   dangerouslyAddModulePathsToTranspile: [
    //     // Ensure that all packages starting with @evanbacon are transpiled.
    //     'dooboo-ui',
    //   ],
    // },
  });
  wUni.output.publicPath = ''
  return wUni
};

Following withUnimodules source for anything that would affect output.publicPath lead to https://github.com/expo/expo-cli/blob/ca0c33e353887da7593a8ce4fa7ad5ef654845b6/packages/webpack-config/src/env/paths.ts#L156, which describes what its doing.

I saw you late. You're right. Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hckhanh picture hckhanh  路  69Comments

ChucKN0risK picture ChucKN0risK  路  74Comments

bpeab picture bpeab  路  70Comments

dependencies[bot] picture dependencies[bot]  路  142Comments

Gongreg picture Gongreg  路  58Comments