簡體   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