Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Storybook iframe.html Failed to load resource #11694

Closed
s-ong-c opened this issue Jul 27, 2020 · 13 comments
Closed

Build Storybook iframe.html Failed to load resource #11694

s-ong-c opened this issue Jul 27, 2020 · 13 comments

Comments

@s-ong-c
Copy link

s-ong-c commented Jul 27, 2020

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

@hyochan
Copy link

hyochan commented Jul 27, 2020

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

@ndelangen
Copy link
Member

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 ndelangen self-assigned this Jul 28, 2020
@s-ong-c
Copy link
Author

s-ong-c commented Jul 28, 2020

@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.

@ndelangen
Copy link
Member

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?

@s-ong-c
Copy link
Author

s-ong-c commented Jul 28, 2020

package.json script

yarn build

build result
스크린샷 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

@ndelangen
Copy link
Member

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

Can you tell me if this statement is correct?
#11694 (comment)

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?

@s-ong-c
Copy link
Author

s-ong-c commented Jul 29, 2020

@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??

@ndelangen
Copy link
Member

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

@shilman shilman closed this as completed Jul 31, 2020
@shilman
Copy link
Member

shilman commented Jul 31, 2020

Try upgrading to 6.0 RC?

npx sb@next upgrade --prerelease

@shilman shilman reopened this Jul 31, 2020
@s-ong-c
Copy link
Author

s-ong-c commented Jul 31, 2020

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.

@Marklb
Copy link
Member

Marklb commented Aug 1, 2020

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.

@s-ong-c
Copy link
Author

s-ong-c commented Aug 4, 2020

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.

@badnutz
Copy link

badnutz commented Sep 17, 2021

I had a similar issue, for me, the resources were not loaded because I set in the .storybook/preview-head.html a tag, after removing it the resources loaded correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants