tcoopman / image-webpack-loader

Image loader module for webpack
MIT License
2.03k stars 131 forks source link

Expected argument to be of type `array` but received type `string` #178

Open S-Masoud-Emamian opened 5 years ago

S-Masoud-Emamian commented 5 years ago

I'm using reactjs. when I want to use png I got this error message:

ERROR in ./app/assets/img/RecieversFormBG1.png
Module build failed (from ./node_modules/image-webpack-loader/index.js):
ArgumentError: Expected argument to be of type `array` but received type `string`
    at input (C:\Users\S.M_Emamian\Desktop\pos\node_modules\imagemin-pngquant\index.js:32:3)
    at <anonymous>
 @ ./app/assets/css/RecieversPanel.css (./node_modules/css-loader!./app/assets/css/RecieversPanel.css) 7:4000-4038
 @ ./app/assets/css/RecieversPanel.css
 @ ./app/containers/Login/index.js
 @ ./app/containers/Login/Loadable.js
 @ ./app/containers/App/index.js
 @ ./app/app.js
 @ multi ./node_modules/react-app-polyfill/ie11.js webpack-hot-middleware/client?reload=true ./app/app.js
"image-webpack-loader": "4.4.0",
sakalx commented 4 years ago

webpack.config.js

instead pngquant: {quality: '65-90', speed: 4}, do this pngquant: {quality: [0.65, 0.90], speed: 4},


  test: /\.(gif|png|jpe?g|svg)$/i,
  use: [
    'file-loader',
    {
      loader: 'image-webpack-loader',
      options: {
        mozjpeg: {
          progressive: true,
          quality: 65
        },
        // optipng.enabled: false will disable optipng
        optipng: {
          enabled: false,
        },
        pngquant: {
          quality: [0.65, 0.90],
          speed: 4
        },
        gifsicle: {
          interlaced: false,
        },
        // the webp option will enable WEBP
        webp: {
          quality: 75
        }
      }
    },
  ],
}]
sergei-zheludkov commented 4 years ago

instead pngquant: {quality: '65-90', speed: 4}, do this pngquant: {quality: [0.65, 0.90], speed: 4},

it's working. thx))

Sushmaa-commits commented 3 years ago

This is my current webpack.server.js. As you can see, I have commented out the entire options object for image-webpack-loader.

  {
        test: /\.(jpg|png|gif)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              // Inline files smaller than 10 kB
              limit: 10 * 1024,
            },
          },
          {
            loader: "image-webpack-loader",
            // options: {
            //   mozjpeg: {
            //     enabled: false,
            //     // NOTE: mozjpeg is disabled as it causes errors in some Linux environments
            //     // Try enabling it i
            //     // Try enabling it in your environment by switching the config to:
            //     // enabled: true,
            //     // progressive: true,
            //   },
            //   gifsicle: {
            //     interlaced: false,
            //   },
            //   optipng: {
            //     optimizationLevel: 7,
            //   },
            //   pngquant: {
            //     quality: [0.65, 0.9],
            //     speed: 4,
            //   },
            // },
          },
        ],
      },

But I am still seeing the same error message.

webpack:///./src/assets/images/play.png?:1 throw new Error("Module build failed (from ./node_modules/image-webpack-loader/index.js):\nArgumentError: Expectedoptions.qualityto be of typearraybut received typestring\n at u (D:\\projectdirectory\\node_modules\\ow\\dist\\source\\index.js:1:12236)\n at D:\\projectdirectory\\node_modules\\imagemin-pngquant\\index.js:35:3\n Can somebody help me look this up? First the quality was like "65-90", I changed it to [0.65,0.9] and still the same error was being thrown. So I commented the whole options block but the output was the same.