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.

Importing font files (*.woff, *.ttf)

See original GitHub issue

Describe the bug

Loading fonts seems to be failing with:

ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/Users/.../node_modules/image-size/dist/index.js:52:11)
    at imageSize (/Users/.../node_modules/image-size/dist/index.js:104:16)

Webpack config shows that the font is being loaded via next-image-loader-stub:

{
    test: /\.(svg|ico|jpg|jpeg|png|apng|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
        use: [
              {
                loader: '/Users/.../node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js',
                options: { filename: 'static/media/[path][name][ext]' }
              }
        ]
  },

Perhaps it’s because font files won’t have a width and height? https://github.com/RyanClementsHax/storybook-addon-next/blob/6583c2080386f72fdebc49ff93a2b8262d1219bc/src/images/next-image-loader-stub.ts#L24

Just guessing… Would love to hear your insights. Thanks!

Your minimal, reproducible example

http://forking.example.on.codesandbox.fails.to.build

Steps to reproduce

  1. add a font static asset
  2. add css that imports font file
  3. storybook start fails

Expected behavior

I expected static file imports to work as before, but next-image-loader-stub seems to be breaking.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OS: MacOS X
  • Node 16

storybook-addon-next version

v1.3.1

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
czebecommented, Feb 4, 2022

Thanks Ryan! Fantastic work! I noticed a different, smaller issue as well. Will open another ticket when I get a chance.

0reactions
github-actions[bot]commented, Feb 4, 2022

🎉 This issue has been resolved in version 1.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

The BEST way to import and upload custom fonts into ...
The best and most SEO optimised way to import and upload your custom ... Find the font files (.woff or .woff2) and upload...
Read more >
Understanding font file formats(ttf, otf, woff, etc)
Understanding font file formats(ttf, otf, woff, etc) ... unpack and use the css provided by them to get a kickstart on importing the...
Read more >
How to convert WOFF font format to TTF on Windows 11/10
Convert WOFF font to TTF file format using this free online font converter tool or command line so that you can use it...
Read more >
How to use @font-face in CSS
Stands for: OpenType Font and TrueType Font. The WOFF format was initially created as a reaction to OTF and TTF, in part, because...
Read more >
Understanding of Font Formats: TTF, OTF, WOFF, EOT & SVG
Compression and subsetting make the font files smaller. ... WOFF is basically OTF or TTF with metadata and compression supported by all major...
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