Cannot load font files referenced in a node_modules css file
See original GitHub issue- Read the docs.
- Use Vite >=2.0. (1.x is no longer supported)
- If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
I’m working on a new project at work, and we’re using a node_modules dependency containing all the company css. The css file itself loads Font Awesome files with relative paths:
@font-face {
font-family: Font Awesome\ 5 Free;
font-style: normal;
font-weight: 400;
font-display: auto;
src: url(../fonts/fa/fa-regular-400.eot);
src: url(../fonts/fa/fa-regular-400.eot?#iefix) format("embedded-opentype"), url(../fonts/fa/fa-regular-400.woff2) format("woff2"), url(../fonts/fa/fa-regular-400.woff) format("woff"), url(../fonts/fa/fa-regular-400.ttf) format("truetype"), url(../fonts/fa/fa-regular-400.svg#fontawesome) format("svg")
}
I import the dependency like this in App.vue
<style lang="scss">
@import "@company/css-library/assets/css/styles.css";
</style>
The issue is that the FA fonts are then loaded relatively to the ./src
folder, which leads to this 404 error in the browser:
GET http://localhost:3000/fonts/fa/fa-solid-900.woff2 net::ERR_ABORTED 404 (Not Found)
How can I solve this?
Reproduction
I cannot share the source, but I guess that the issue will arise with any css in a node_modules dep, that will load a font file with a relative path.
System Info
vite
version: ^2.0.0-beta.34- Operating System: Windows 7
- Node version: 12.16.3
- Package manager (npm/yarn/pnpm) and version: npm 6.14.4
Logs (Optional if provided reproduction)
vite:config bundled config file loaded in 376ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'alias',
vite:config 'vite:dynamic-import-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:vue',
vite:config 'vite:css-post',
vite:config 'vite:build-html',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'vite:define',
vite:config 'rollup-plugin-dynamic-import-variables',
vite:config 'vite:import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:terser',
vite:config 'vite:size'
vite:config ],
vite:config alias: [
vite:config {
vite:config find: /^\/@vite\//,
vite:config replacement: 'C:\\Users\\[redacted]\\node_modules\\vite\\dist\\client/'
vite:config },
vite:config {
vite:config find: '@',
vite:config replacement: 'C:\\Users\\[redacted]\\src'
vite:config }
vite:config ],
vite:config build: {
vite:config base: '/',
vite:config target: [ 'es2019', 'edge16', 'firefox60', 'chrome61', 'safari11' ],
vite:config polyfillDynamicImport: true,
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config sourcemap: false,
vite:config rollupOptions: {},
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config minify: 'terser',
vite:config terserOptions: {},
vite:config cleanCssOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false
vite:config },
vite:config define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
vite:config ssr: { external: [ 'vue', '@vue/server-renderer' ] },
vite:config configFile: '/Users/[redacted]/vite.config.ts',
vite:config inlineConfig: {
vite:config root: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config build: {}
vite:config },
vite:config root: '/Users/[redacted]',
vite:config command: 'build',
vite:config mode: 'production',
vite:config isProduction: true,
vite:config optimizeCacheDir: '\\Users\\[redacted]\\node_modules\\.vite',
vite:config server: {},
vite:config env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen]
vite:config }
vite:config } +12ms
building for production...
[vite:css] ENOENT: no such file or directory, open 'C:\Users\[redacted]\fonts\fa\fa-regular-400.eot'
file: /Users/[redacted]/src/App.vue?vue&type=style&index=0&lang.scss
error during build:
Error: ENOENT: no such file or directory, open 'C:\Users\[redacted]\fonts\fa\fa-regular-400.eot'
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Load fonts with Webpack and font-face - css - Stack Overflow
Show activity on this post. I'm trying to load a font in my CSS file using @font-face but the font never loads. This...
Read more >Sass: @import
When a file with @use rules is imported, all the CSS transitively loaded by those is included in the resulting stylesheet, even if...
Read more >css-loader | webpack - JS.ORG
js can load CSS files, embed small PNG/JPG/GIF/SVG images as well as fonts as Data URLs and copy larger files to the output...
Read more >Importing 3rd Party CSS + Image Paths > Webpack Encore
Internally, the FontAwesome CSS file references some font files that the user's browser needs to download: these files here. But... these files aren't...
Read more >Load images and fonts with Webpack file loader like a pro
Webpack file-loader is a loader used mainly for supporting images such as SVG and PNG, and fonts in your webpack project. If your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s the same issue as #1629 and is fixed in beta.37.
It works for
npm run dev
but fails fornpm run build
with a weird error:And if I add an
any
type tot
, it obviously tells me that typings are for .ts files…I’ll continue with my workaround in the meantime, thank you though 😃