Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

The browser rejects fonts built by webpack with OTS parsing error

ErrorOTS parsing error

Short answer

OTS parsing error means the browser got a file that is not a valid font. In webpack 5, add one asset/resource rule for font extensions, check that output.publicPath points to where the font files are served, and stop an old file-loader rule from processing the same files again.

  • Applies to webpack 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the font URL from the browser's network tab in a new tab. If you see an HTML page or a 404, the file path is wrong. If the file downloads, check the build rule.

    ls dist/ dist/fonts/
  2. 2Match what you see, then jump to its fix

    1. 1No font files in dist, or the build fails on the font importNo rule emits the font filesFix
    2. 2The font request returns an HTML page or a 404The public path points to the wrong placeFix
    3. 3Duplicated or broken font files after a webpack 5 upgradeAn old file-loader rule processes the fonts a second timeFix

What does the error look like?

  • OTS parsing error

Cause 1 of 3

No rule emits the font files

1Check

Webpack 5 handles files through asset modules. Without a rule for the font extensions, fonts are not emitted as files.

grep -n "woff\|ttf\|asset" webpack.config.js

2Fix

Add an asset/resource rule that matches font formats. It emits each file and injects its URL into the bundle. Use generator.filename to put them in a folder.

{
  test: /\.(woff2?|eot|ttf|otf)$/i,
  type: 'asset/resource',
  generator: {
    filename: 'fonts/[hash][ext][query]',
  },
},

3Verify

Rebuild. The font files now exist in dist/fonts.

npx webpack
ls dist/fonts

Confirmed by webpack.js.org

Did this fix it?

Cause 2 of 3

The public path points to the wrong place

1Check

Assets are loaded from output.publicPath joined with the file name. If the site serves the files from another URL, the browser downloads something that is not a font.

grep -n "publicPath" webpack.config.js

2Fix

Set output.publicPath to the URL the assets are really served from.

output: {
  publicPath: 'https://cdn.example.com/assets/',
},

3Verify

Rebuild and request one font URL directly. It returns the file.

curl -I https://cdn.example.com/assets/fonts/example.woff2

Confirmed by webpack.js.org

Did this fix it?

Cause 3 of 3

An old file-loader rule processes the fonts a second time

1Check

If you kept file-loader or url-loader during migration, Asset Modules process the same files again and can duplicate assets.

grep -n "file-loader\|url-loader" webpack.config.js package.json

2Fix

Replace the old loader with asset/resource. If you must keep it for now, set type to javascript/auto on that rule.

{
  test: /\.(woff2?|eot|ttf|otf)$/i,
  use: ['file-loader'],
  type: 'javascript/auto',
},

3Verify

Rebuild and check that each font appears once in dist.

ls dist/ dist/fonts/

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • Use asset modules, not file-loader and url-loader, in a new webpack 5 setup.
  • Set output.publicPath explicitly for every environment.
  • Open a font URL directly in the browser after the first deploy.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.