GithubHelp home page GithubHelp logo

Comments (10)

ignas-sedunovas avatar ignas-sedunovas commented on July 17, 2024 2

Thanks for looking into this, @mrmckeb. Here's the repo: https://github.com/ignas-sedunovas/storybook-preset-create-react-app-issue.

Some details that might be helpful:

  • I added CRA + TS and Storybook. Then I wrote a story. At this point fonts are rendering correctly both in local server and static file (repo at this commit) βœ”
  • Then I converted the story to TSX and added @storybook/preset-create-react-app addon. At this point Storybook complained about missing Webpack loaders. Therefore, I moved the story under /src folder. Now the Storybook successfully loads the story. Unfortunately, when I use the static build, the font is not loaded because of incorrect path (see image below) ❌

image

from presets.

functionalDev avatar functionalDev commented on July 17, 2024 2

this issue seems to be a dublication of storybookjs/storybook#9564
I found a workaround by adjusting the config for the file-loader in main.js

const getFileLoader = (config) => {
  const { oneOf } = config.module.rules.find(({oneOf}) => oneOf);
  return oneOf.find(({loader}) => /file-loader/.test(loader));
};
module.exports = {
  stories: ['../src/stories/*.stories.js'],
  addons: [
    '@storybook/preset-create-react-app',
  ],
  webpackFinal:  async (config) => {
    const getFileLoader = (config) => {
      const { oneOf = [] } = config.module.rules.find(({ oneOf }) => oneOf);
      return oneOf.find(({loader}) => /file-loader/.test(loader));
    };
    
    const mutateLoaderToMakePathAbsolute = (loader) => {
        if(loader && loader.options && loader.options.name) {
          loader.options.name = '/' + loader.options.name;
        }
    };

    const fileLoader = getFileLoader(config);
    mutateLoaderToMakePathAbsolute(fileLoader);
    return config;
  },
};

from presets.

mrmckeb avatar mrmckeb commented on July 17, 2024

Hi @ignas-sedunovas, I think I understand the problem here. We're now fully using the CRA webpack config, instead of relying on a mix of CRA and Storybook - as this caused a lot of issues.

Are you able to provide a minimal repro repo? I can then take a look and resolve this one.

from presets.

VojGin avatar VojGin commented on July 17, 2024

The same happens to me for images linked from CSS files

image

Bez názvu

from presets.

mrmckeb avatar mrmckeb commented on July 17, 2024

Hi @ignas-sedunovas and @VojGin - I'm very sorry for the long time between replies. I was away on business.

I think this is likely caused by the CRA preset's implementation of file-loader, but I need to investigate more to understand why. The repo provided above will be very helpful @ignas-sedunovas.

It may be as simple as redefining the static path...

I'll be able to look later this week - but if anyone can take a look beforehand, that would be greatly appreciated.

from presets.

zeorin avatar zeorin commented on July 17, 2024

I'm also having this problem. In my case Storybook is not served on the root path, instead on /components behind Nginx. How might I fix this in a relative-url manner?
I tried loader.options.name = '../../' + loader.options.name;, which fixes the import path, but doesn't actually include the files in the output.

from presets.

mrmckeb avatar mrmckeb commented on July 17, 2024

This should now be solved in the latest release. Can someone please test?

If using the preset, we strongly recommend you don't have any custom Webpack config.

from presets.

ocean90 avatar ocean90 commented on July 17, 2024

@mrmckeb Thanks, confirmed that it's now working with 2.1.1.

from presets.

mrmckeb avatar mrmckeb commented on July 17, 2024

Thank you! WIll close this off.

from presets.

andrewmadridista avatar andrewmadridista commented on July 17, 2024

Hello. Issue is reproduced with the new versions:
"@storybook/react": "6.0.22",
"@storybook/preset-create-react-app": "3.1.4",
"react-scripts": "3.4.3"
Adjusting the config for the file-loader in main.js still fixes the issue.

from presets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.