gpt4 book ai didi

gulp-imagemin:无法加载默认插件 xxx

转载 作者:行者123 更新时间:2023-12-05 01:45:18 25 4
gpt4 key购买 nike

环境:

  • Windows 7
  • 节点 6.9.5

我使用类似 this npm 的插件.但我得到一个错误。从一些视频来看,这是正确的。是相对于imagemin的版本?

// gulpfile.js

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');

var app = {
srcPath: 'src/',
devPath: 'build/',
prdPath: 'dist/', //生产部署
}
gulp.task('image', function() {
gulp.src(app.srcPath + 'image/**/*')
.pipe(gulp.dest(app.devPath + 'image'))
.pipe(imagemin())
.pipe(gulp.dest(app.prdPath + 'image'))
})

当我“吞下图像”时,出现错误:

[13:05:56] Using gulpfile ~\Desktop\study\angularapp\gulpfile.js
[13:05:56] Starting 'image'...
[13:05:56] Finished 'image' after 6.96 ms
[13:05:56] gulp-imagemin: Couldn't load default plugin "gifsicle"
[13:05:56] gulp-imagemin: Couldn't load default plugin "jpegtran"
[13:05:56] gulp-imagemin: Couldn't load default plugin "optipng"
[13:05:56] gulp-imagemin: Minified 1 image (saved 0 B - 0%)

我使用npm install imagemin-optipng,但还是不行。像这样的依赖:

"devDependencies": {
"clean-css": "^4.0.5",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.1",
"gulp-connect": "^5.0.0",
"gulp-cssmin": "^0.1.7",
"gulp-imagemin": "^3.1.1",
"gulp-less": "^3.3.0",
"gulp-load-plugins": "^1.5.0",
"gulp-uglify": "^2.0.1",
"lodash": "^4.17.4",
"open": "^0.0.5"

这是怎么回事?

最佳答案

我有同样的问题,我发现这是因为默认插件没有正确安装。

npm install imagemin-jpegtran imagemin-svgo imagemin-gifsicle imagemin-optipng --save

此警告是由这些行代码 #L12 引发的

const loadPlugin = (plugin, args) => {
try {
return require(`imagemin-${plugin}`).apply(null, args);
} catch (err) {
gutil.log(`gulp-imagemin: Couldn't load default plugin "${plugin}"`);
}
};

如果在 catch 中记录错误,我们可以看到 Module not found xxx

try {
return require(`imagemin-${plugin}`).apply(null, args);
} catch (err) {
console.log(err); // and will throw error: XX Module Not Found
gutil.log(`gulp-imagemin: Couldn't load default plugin "${plugin}"`);
}

所以我们可以安装丢失的包。

如果还有一些错误,只需重新安装imagemin

npm uninstall gulp-imagemin --save
npm install gulp-imagemin --save

关于gulp-imagemin:无法加载默认插件 xxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42152008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com