繁体   English   中英

gulp-install不能用乙烯基文件安装依赖项

[英]gulp-install not install the dependencies with vinyl file

我是gulp插件的初学者。 我想通过合并的package.json安装依赖项。 代码如下。

gulp.task('install-dependencies', function () {
    var through = require('through2');
    var npm = require('npm');
    var Promise = require('bluebird');
    var file = require('gulp-file');
    var install = require('gulp-install');
    var path = require('path');
    var npmLoad = Promise.promisify(npm.load);
    var plugins = {};

    //for test
    var lastFile;

    gulp.src([`${PATH.plugin}**/package.json`])
        .pipe(through.obj(function parse_plugins(file, enc, cb) {
            if (file.isNull()) {
                cb();
                return;
            }

            if (file.isStream()) {
                this.emit('error', new gulpUtil.PluginError('package-concat', 'Streaming not supported'));
                cb();
                return;
            }
            let fileContent = {};
            try {
                fileContent = JSON.parse(file.contents.toString())
            } catch (e) {
                this.emit('error', new gulpUtil.PluginError('package-concat', `file '${file.path}' not a json file!`));
                throw e;
            }
            plugins = Object.assign({}, plugins, fileContent.dependencies)
            lastFile = file;
            cb();
        },
        function install(cb){
            let fileContent = {};
            fileContent.name = "test";
            fileContent.dependencies = plugins;
            var file = new gulpUtil.File({
                base: path.join(__dirname, './'),
                cwd: __dirname,
                path: path.join(__dirname, './package.json'),
                contents: new Buffer(JSON.stringify(fileContent))
            });
            this.push(file);
            cb();
        }
    ))
    .pipe(install());
})

但是,依赖项未按预期安装。 和日志如下。

[14:50:37]正在启动“安装依赖项” ...

[14:50:37] 205毫秒后完成“安装依赖项”

npm WARN可选跳过跳过可选依赖项/ chokidar / fsevents失败:

npm WARN notsup与您的操作系统或体系结构不兼容:fsevents@1.0.11

您的操作系统是什么?

您可能会在这里找到类似的东西

听起来您可以尝试卸载所有内容,然后从头开始重新安装(或者只是删除node_module文件夹并使用npm install)。 但是不确定,根据错误本身,它在很大程度上取决于您的操作系统。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM