patrickhulce / fontmin-webpack

Minifies icon fonts to just the used glyphs.
MIT License
139 stars 19 forks source link

Cannot read property 'contents' of undefined during build #17

Closed Limoncelo closed 5 years ago

Limoncelo commented 5 years ago

Using webpack v 4.29.6, my build fails at fontmin-webpack/lib/index.js:129, I get this error :

byExtension[item.extension].contents

TypeError: Cannot read property 'contents' of undefined

Here is some of my webpack config file : (I am also loading some .gif and .png files with file-loader, maybe it's causing a conflict?)

module.exports = {
    mode: 'production',
    entry: entryObject,
    module: {
        rules: [
            {
                test: /(\.scss)$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader
                    },
                    {
                        loader: "css-loader" 
                    },
                    {
                        loader: "sass-loader",
                        options: {
                            implementation: require("node-sass")
                        }
                    }, 
                    {
                        loader: "postcss-loader",
                    }
                ]
            },
            {
                test: /\.(woff(2)?|ttf|eot|svg|gif|png)(\?v=\d+\.\d+\.\d+)?$/,
                use: [{
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: '../fonts/'
                        }
                    }]
            },
        ]
    },
    plugins:
            [
                new MiniCssExtractPlugin({
                    filename: "../css/[name].css",
                    chunkFilename: "[id].css",
                }),
                new OptimizeCSSAssetsPlugin({}),
                new FontminPlugin({
                    autodetect: true, // automatically pull unicode characters from CSS
                }),
            ],
    devtool: false,
    }

}
patrickhulce commented 5 years ago

Thanks for filing @Limoncelo!

I think it is the grouping of gif and png with fonts that is messing things up. Do you have images that share the same base file name with your font files? That's how we detect different formats of the same font.

Limoncelo commented 5 years ago

Thanks for the quick reply @patrickhulce !

Yes, I have an svg file in one of my dependencies that has the same name as font files... Do you have a workaround for that?

patrickhulce commented 5 years ago

Hm, svg should work just fine. You're sure there's not a png or gif with the same name as a font?

Limoncelo commented 5 years ago

I checked my dependencies, there are some png and gif files loaded, but none of them have the same name as a font...

patrickhulce commented 5 years ago

Hm, OK well I can take a stab at what I think might fix the problem, but without a repro on my end it will be hard to say for sure what's going on :/

Limoncelo commented 5 years ago

Sorry about the late reply, I can't publish my entire code, but maybe the list of my dependencies can help? Or if you have any suggestion of how I can try to debug it by myself? Thanks a lot!


  "devDependencies": {
    "@babel/core": "^7.3.4",
    "@babel/preset-env": "^7.3.4",
    "autoprefixer": "^9.4.9",
    "babel-loader": "^8.0.5",
    "babel-minify-webpack-plugin": "^0.3.1",
    "babel-preset-es2015": "^6.24.1",
    "css-loader": "^2.1.0",
    "file-loader": "^3.0.1",
    "fontmin-webpack": "^2.0.3",
    "glob": "^7.1.3",
    "hard-source-webpack-plugin": "^0.13.1",
    "imports-loader": "^0.8.0",
    "jquery": "^3.3.1",
    "mini-css-extract-plugin": "^0.5.0",
    "node-sass": "^4.11.0",
    "optimize-css-assets-webpack-plugin": "^5.0.1",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-loader": "^3.0.0",
    "postcss-preset-env": "^6.6.0",
    "sass-loader": "^7.1.0",
    "uglify-es": "git://github.com/mishoo/UglifyJS2.git#harmony",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.8.1",
    "animate.css": "^3.7.0",
    "blueimp-file-upload": "^9.31.0",
    "bootstrap": "^4.3.1",
    "clipboard": "^2.0.4",
    "ekko-lightbox": "^5.3.0",
    "flexslider": "^2.7.2",
    "gsap": "^2.1.3",
    "intl-tel-input": "^15.0.1",
    "jquery-mask-plugin": "^1.14.15",
    "jquery.maskedinput": "^1.4.1",
    "js-cookie": "^2.2.0",
    "lightgallery.js": "^1.1.3",
    "mixitup": "^3.3.1",
    "pace": "^0.0.4",
    "pace-progress": "^1.0.2",
    "pickadate": "^3.6.2",
    "popper.js": "^1.14.7",
    "select2": "^4.0.6-rc.1",
    "slick-carousel": "^1.8.1",
    "sweetalert": "^2.1.2"
  }
patrickhulce commented 5 years ago

Have you given it a shot with v2.0.4? I published what should be a fix for this error message but didn't have a bug repro so 🤷‍♂

Limoncelo commented 5 years ago

Yes it works! Thank you for your help! :)

patrickhulce commented 5 years ago

Great!