question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

font file URL wrong for imported font package

See original GitHub issue

Describe the bug I’m using an installed typeface package, similar to typeface-roboto in my create-react-app app. I’m importing it for use in storybook in .storybook/preview.js, import 'typeface-roboto'. This works fine when running storybook with start-storybook. However when I build it, storybook is trying to load the font from the wrong location. The font is located at static/media/[name].[hash:8].[ext] whereas storybook is looking for it at static/media/static/css/[name].[hash:8].[ext], so is returning a 404.

I’m not sure if this is a problem with storybook, webpack or create-react-app.

The only custom webpack config I have is an alias, and I’ve tried various custom webpack configs after browsing other similar issues here. the closest I’ve come is building the files in the correct location, but the hash is different to what storybook is looking for, and I don’t know how I can change the expected URL, or what’s creating it in the first place.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://github.com/robphoenix/storybook-issue
  2. Clone repo
  3. Install dependencies; yarn
  4. Run app, yarn start, and see the heading using the Roboto typeface
  5. Run storybook, yarn storybook and see the Heading story using the Roboto typeface
  6. Build storybook, yarn build-storybook, and serve, yarn serve-storybook and see the Heading story not using the Roboto typeface
  7. open the console in dev tools and see the error: Failed to load resource: the server responded with a status of 404 (Not Found), and hover over the font filename to see the URL, it should be localhost:5000/static/css/static/media
  8. in the terminal see that the fonts are in storybook_build/static/media

Expected behavior Fonts to load.

System: Please paste the results of npx -p @storybook/cli@next sb info here.

System:
    OS: macOS 10.15.2
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 13.5.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 79.0.3945.117
    Firefox: 71.0
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-actions: ^5.3.7 => 5.3.7
    @storybook/addon-links: ^5.3.7 => 5.3.7
    @storybook/addons: ^5.3.7 => 5.3.7
    @storybook/preset-create-react-app: ^1.5.2 => 1.5.2
    @storybook/react: ^5.3.7 => 5.3.7

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
robcaldecottvelocommented, Jan 30, 2020

I found a dirty workaround: add the following to your package.json:

"homepage": "./"
3reactions
robphoenixcommented, Apr 16, 2020

@mrmckeb can confirm my original issue is fixed after updating my dependencies

 "@storybook/preset-create-react-app": "^2.1.1",
 "@storybook/react": "^5.3.18",

many thanks 🙏 🌈

I’m going to close this as anything else should probably go in a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Font not changing in CSS even after importing - Stack Overflow
I added this to my CSS: @font-face { font-family: "Poppins"; src: url("/fonts/Poppins-SemiBold.ttf") format("true type"), url("/fonts/Poppins- ...
Read more >
Custom Fonts Not Displaying On Front End - Elementor
If you've recently migrated from HTTP to HTTPS, your font files may need to be re-uploaded, so they are being served from HTTPS....
Read more >
Using web fonts – Fonts Knowledge - Google Fonts
Loading font files, referencing them, and assigning weights and styles. ... not be a space between url and the opening parenthesis—this is a...
Read more >
CSS @font-face Rule - W3Schools
Specify a font named "myFirstFont", and specify the URL where it can be found: ... a name for the font (e.g. myFirstFont), and...
Read more >
Loading Fonts with webpack - Chris Courses
If you're currently using webpack to manage your CSS, importing font files won't work without a little bit of extra configuration.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found