Open jlounds opened 4 months ago
This stack-overflow answer led me to the solution that fixed it for me. In your webpack-config change this:
{
test: /\.ttf$/,
loader: "url-loader", // or directly file-loader
include: path.resolve(__dirname, "node_modules/react-native-vector-icons"),
}
to this:
{
test: /\.ttf$/,
type: 'asset/resource',
include: path.resolve(__dirname, "node_modules/react-native-vector-icons"),
}
This should probably also be updated in the readme.
Environment
Description
Web fonts for the icons are not being downloaded / interpreted by Firefox, Chrome, or Safari and only show the dreaded square box. (Firefox shows a Unicode number as well)
Firefox error message in developer tools console:
Chrome:
I confirmed that the file in /static/media is being downloaded. In fact, I tried uploading it to https://transfonter.org/ to see if I could convert it to a different format and manually add it, but even that failed saying the "Font file is corrupted."
Code
I tried following the instructions in the readme, but I think Expo and/or the version of webpack is complicating things. But since I am new to all of this, I don't know how to narrow it down.
module.exports = async function (env, argv) { const config = await createExpoWebpackConfigAsync(env, argv); config.module.rules.push( { test: /.ttf$/, loader: "url-loader", include: path.resolve(__dirname, "node_modules/react-native-vector-icons"), } ); return config; };
import materialCommunityIconFont from 'react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf'; const moreFonts =
@font-face { src: url(${materialCommunityIconFont}); font-family: "MaterialCommunityIcons"; }
;const moreFontsStyle = document.createElement('style'); moreFontsStyle.type = 'text/css';
if (moreFontsStyle.styleSheet) { moreFontsStyle.styleSheet.cssText = moreFonts; } else { moreFontsStyle.appendChild(document.createTextNode(moreFonts)); } document.head.appendChild(moreFontsStyle);