patrickhulce / fontmin-webpack

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

TypeError: content.match is not a function #53

Open Abdull opened 2 years ago

Abdull commented 2 years ago

Using

npm: 8.4.0
webpack: 5.52.1
fontmin-webpack: 3.2.0

I set up FontminPlugin in my webpack project as per its documentation (following reduced to minimal setup):

const FontminPlugin = require('fontmin-webpack');

module.exports = {
  entry: 'my-entry.js',
  output: {
    // ...
  },
  plugins: [
    // ...
    new FontminPlugin({
      autodetect: true
    })
  ],
}

I get the following TypeError when running my webpack build:

$ npm run build

> myproject@1.0.0 build
> webpack

myproject/node_modules/fontmin-webpack/lib/index.js:117
        const matches = content.match(GLYPH_REGEX) || []
                                ^

TypeError: content.match is not a function
    at myproject/node_modules/fontmin-webpack/lib/index.js:117:33
    at arrayMap (myproject/node_modules/lodash/lodash.js:653:23)
    at Function.map (myproject/node_modules/lodash/lodash.js:9622:14)
    at interceptor (myproject/node_modules/lodash/lodash.js:17094:35)
    at Function.thru (myproject/node_modules/lodash/lodash.js:8859:14)
    at myproject/node_modules/lodash/lodash.js:4430:28
    at arrayReduce (myproject/node_modules/lodash/lodash.js:697:21)
    at baseWrapperValue (myproject/node_modules/lodash/lodash.js:4429:14)
    at LodashWrapper.wrapperValue (myproject/node_modules/lodash/lodash.js:9114:14)
    at FontminPlugin.findUnicodeGlyphs (myproject/node_modules/fontmin-webpack/lib/index.js:138:8)
patrickhulce commented 2 years ago

Thanks for filing @Abdull! Would you mind sharing what's in your // ... and entry file?

Our test cases look exactly like our readme and are passing on webpack 5, so I suspect interplay with another plugin or content type.

ArTiSTiX commented 2 years ago

I had this issue using another plugin MiniCssExtractPlugin.

My solution was to put the Fontmin-Webpack plugin before MiniCssExtractPlugin and it disappeared.

ENV: using the Asset Modules and no file-loader, with Webpack@5.65.0, MiniCssExtractPlugin@2.4.5

qiutian00 commented 6 months ago

I have the same problem

patrickhulce commented 6 months ago

@qiutian00 did the advice of other posters to respect the order of plugins in the example work?

What other plugins are you using?

qiutian00 commented 6 months ago

@qiutian00 did the advice of other posters to respect the order of plugins in the example work?

What other plugins are you using?

Not solved this problem, finally, I use the online site to convert font https://transfonter.org/