webpack Can't resolve '../../assets/icon-font/icomoon.eot?e3uwku' in 'D:\sudi\aa-Server-side-render\MAPS101_Fresh_ssr\src\scss'

Viewed 694

I want to implement SSR in an already build react application. I am trying to include icon-fonts and ignore CSS files from node_modules of a particular library

Please help me, I am stuck here!!

I'm trying to load a font in my SCSS file but giving the below error.

enter image description here

my folder structure is :

enter image description here

my webpack.config.js is:

    const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {

    // webpack optimization mode
    mode: ('development' === process.env.NODE_ENV ? 'development' : 'production'),

    // entry files
    entry: 'development' === process.env.NODE_ENV ? [
        './src/index.js', // in development
    ] : [
        './src/index.js', // in production
    ],

    // output files and chunks
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'build/[name].js',
    },

    // module/loaders configuration
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react']
                    }
                },
                exclude: [/node_modules/, /static/]
            },
            {
                test: /\.(sa|sc|c)ss$/,
                use: [
                    true ? 'style-loader' : MiniCssExtractPlugin.loader,
                    'css-loader',
                    'postcss-loader',
                    'sass-loader',
                ],
                exclude: [/node_modules/, /static/]
            },
            {
                test: /\.(css)$/,
                use: [{
                    loader: MiniCssExtractPlugin.loader,
                    options: {
                        publicPath: '/public/css'
                    }

                }, 'css-loader'],
                exclude: [/node_modules/, /static/]
            },



            
            {
                test: /\.(jpg|jpeg|png|svg|gif)$/,
                use: [{
                    loader: 'file-loader',
                    options: {
                        name: '[md5:hash:hex].[ext]',
                        publicPath: '/public/img',
                        outputPath: 'img'
                    }
                }]
            },
            {
                test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
                use: 'url-loader?limit=10000&mimetype=application/font-woff',
            },
            {
                test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
                use: 'url-loader?limit=10000&mimetype=application/font-woff',
            },
            {
                test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
                use: 'url-loader?limit=10000&mimetype=application/octet-stream',
            },
            {
                test: /\.otf(\?v=\d+\.\d+\.\d+)?$/,
                use: 'url-loader?limit=10000&mimetype=application/octet-stream',
            },
            {
                test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
                use: 'url-loader?limit=10000&mimetype=application/vnd.ms-fontobject',
            },

        ]
    },

    // webpack plugins
    plugins: [
        // extract css to external stylesheet file
        new MiniCssExtractPlugin({
            filename: 'build/styles.css'
        }),

        // prepare HTML file with assets
        new HTMLWebpackPlugin({
            filename: 'index.html',
            template: path.resolve(__dirname, 'src/index.html'),
            minify: false,
        }),

        // copy static files from `src` to `dist`
        new CopyWebpackPlugin({
            patterns: [
                {
                    from: path.resolve(__dirname, 'src/assets'),
                    to: path.resolve(__dirname, 'dist/assets')
                }
            ]
        }),
    ],

    // resolve files configuration
    resolve: {

        // file extensions
        extensions: ['.js', '.jsx', '.css', '.scss'],
    },
    // webpack optimizations
    optimization: {
        splitChunks: {
            cacheGroups: {
                default: false,
                vendors: false,

                vendor: {
                    chunks: 'all', // both : consider sync + async chunks for evaluation
                    name: 'vendor', // name of chunk file
                    test: /node_modules/, // test regular expression
                }
            }
        }
    },
    // development server configuration
    devServer: {
        port: 8088,
        historyApiFallback: true,
    },        // generate source map
    devtool: 'source-map'    }; 
1 Answers

For me, I had the icomoon font in fonts directory. Did some investigation and found that the .scss file was trying to link it like this url("./assets/styles/fonts/icomoon.svg?y2smka#icomoon"). The problem with that is icomoon.svg?y2smka#icomoon does not exist. So I looked in the fonts directory and found that it's called icomoon.eot

Solution: In your _fonts.scss file, change all url("./assets/styles/fonts/icomoon.svg?y2smka#icomoon"). to url("./icomoon.eot")

Related