Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crashed due to could not load default plugin mozjpeg and no images minfied #380

Open
GrassBlock1 opened this issue Jul 18, 2023 · 3 comments

Comments

@GrassBlock1
Copy link

as titled.
My problem was like #377, but I correctly import the modules needed as shown in the gulp ESM.

my gulpfile.mjs
import gulp from "gulp";
import imagemin, {mozjpeg, optipng} from "gulp-imagemin";
import debug from "gulp-debug";


gulp.task('minify-img', function() {
    return (gulp.src(['./img/*', './img/*/*', "./img/*/*/*"])
        .pipe(debug(imagemin([
            optipng({optimizationLevel: 6}),
            mozjpeg({quality: 85, progressive: true}),
        ])))
        .pipe(gulp.dest('./opt/img')))
});

gulp.task("build", gulp.series("minify-img"));

But gulp-imagemin still crashed with:

TypeError in plugin "gulp-imagemin"
Message:
    function_ is not a function

I tried to debug with gulp-debug and run again, and finally I got gulp-imagemin: Could not load default plugin mozjpeg, and no images within the folder was minfied.

Does anybody has some solution for the issue?

@mzachdev
Copy link

mzachdev commented Nov 20, 2023

I'm on Windows 11.

Latest version of imagemin and gulp. Getting the same error myself. I've tried so many different combinations of code to see if it's something on my end, but this does seem to be a bug.

My error log:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'imagemin-mozjpeg' imported from C:\Users\mzachdev\shopify-sites\gulpfile.mjs
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:887:9)
    at moduleResolve (node:internal/modules/esm/resolve:936:20)
    at defaultResolve (node:internal/modules/esm/resolve:1129:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'

@luchanan
Copy link

it's work for me, if you are use cnpm.

in package.json, you should remove optipng-bin, gulp-imagemin then run this:

rm -rf node_modules
npm install
cnpm i optipng-bin -D
cnpm i gulp-imagemin -D

@BlackStar1991
Copy link

BlackStar1991 commented Apr 15, 2024

I have the same problem for Windows 10.
It showed that your packeg use pngjs2 and it don't support it.

npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. npm WARN deprecated pngjs2@1.2.0: pngjs2 has now taken over the original pngjs package on npm. Please change to use pngjs dependency, version 2+. npm WARN cleanup Failed to remove some directories [ npm WARN cleanup [ npm WARN cleanup 'D:\\OSPanel\\domains\\sneakers.loc\\wp-content\\themes\\sneakers\\markup-template\\node_modules\\svgo', npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'D:\OSPanel\domains\sneakers.loc\wp-content\themes\sneakers\markup-template\node_modules\svgo\node_modules'] { npm WARN cleanup errno: -4048, npm WARN cleanup code: 'EPERM', npm WARN cleanup syscall: 'rmdir', npm WARN cleanup path: 'D:\\OSPanel\\domains\\sneakers.loc\\wp-content\\themes\\sneakers\\markup-template\\node_modules\\svgo\\node_modules' npm WARN cleanup } npm WARN cleanup ] npm WARN cleanup ] npm ERR! code 1 npm ERR! path D:\OSPanel\domains\sneakers.loc\wp-content\themes\sneakers\markup-template\node_modules\pngquant-bin npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node lib/install.js npm ERR! fs.js:44 npm ERR! } = primordials; npm ERR! ^ npm ERR! npm ERR! ReferenceError: primordials is not defined npm ERR! at fs.js:44:5 npm ERR! at req_ (D:\OSPanel\domains\sneakers.loc\wp-content\themes\sneakers\markup-template\node_modules\natives\index.js:143:24) npm ERR! at Object.req [as require] (D:\OSPanel\domains\sneakers.loc\wp-content\themes\sneakers\markup-template\node_modules\natives\index.js:55:10) npm ERR! at Object.<anonymous> (D:\OSPanel\domains\sneakers.loc\wp-content\themes\sneakers\markup-template\node_modules\decompress\node_modules\graceful-fs\fs.js:1:37) npm ERR! at Module._compile (node:internal/modules/cjs/loader:1369:14) npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) npm ERR! at Module.load (node:internal/modules/cjs/loader:1206:32) npm ERR! at Module._load (node:internal/modules/cjs/loader:1022:12) npm ERR! at Module.require (node:internal/modules/cjs/loader:1231:19) npm ERR! at require (node:internal/modules/helpers:179:18) npm ERR! npm ERR! Node.js v20.12.2

I used the last version "gulp-imagemin": "^9.0.0", and "pngquant-bin": "^8.0.1",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants