聚合物:构建时的吞咽错误:合并流 [英] Polymer: gulp error at build time: merge-stream

查看:99
本文介绍了聚合物:构建时的吞咽错误:合并流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着运行 gulp 来构建像Rob Dodson这样的应用程序在这里解释,但我得到以下错误:


  module.js:327 
throw err;
^错误:无法在Function.Module._resolveFilename(module.js:325:15)处找到模块'merge-stream'

在Function.Module._load(module.js:276 :25)
at Module.require(module.js:353:17)
at require(internal / module.js:12:17)
at Object。< anonymous> (/Users/path/to/gulpfile.js:16:21)
在Module._compile(module.js:409:26)
在Object.Module._extensions..js(module.js :416:10)
at Module.load(module.js:343:32)
at Function.Module._load(module.js:300:12)
at Module.require
at require(internal / module.js:12:17)




看起来有一些需要的模块名为 merge-stream ?它是否正确?如果是这样,我在哪里以及如何获得这个模块?或者是否有其他问题导致这种情况?



我刚刚从示例代码Rob中复制了文件 package.json polymer.json gulpfile.js 在这里提供



gulpfile.js

 'use strict'; 

//有关PolymerProject内容的文档。
const path = require('path');
const gulp = require('gulp');
const mergeStream = require('merge-stream');
const del = require('del');
const polymerJsonPath = path.join(process.cwd(),'polymer.json');
const polymerJSON = require(polymerJsonPath);
const polymer = require('polymer-build');
const polymerProject = new polymer.PolymerProject(polymerJSON);
const buildDirectory ='build / bundled';
$ b / **
*等待给定的ReadableStream
* /
函数waitFor(stream){
返回新的Promise((resolve,reject) => {
stream.on('end',resolve);
stream.on('error',reject);
}); $(


函数build(){
返回新的Promise((resolve,reject)=> {
//好的,我们做的第一件事是清楚的build
console.log(`删除build / directory ...`); $ b $ del([buildDirectory])
.then(_ => {
//好的,现在可以让你的源文件
let sourcesStream = polymerProject.sources()
//哦,你是否想要缩小内容? gulpif work
.pipe(polymerProject.splitHtml())
.pipe(gulpif(/\.js$/,uglify()))
.pipe(gulpif(/ \。 css $ /,cssSlam()))
.pipe(gulpif(/\.html$/,htmlMinifier()))
.pipe(polymerProject.rejoinHtml());

//好吧现在让我们对你的依赖做同样的事情
让depsStream = polymerProject.dependencies()
.pipe(polymerProject.splitHtml())
.pipe(gulpif(/ \\.js $ /,uglify ())
.pipe(gulpif(/\.css$/,cssSlam()))
.pipe(gulpif(/\.html$/,htmlMinifier()))
.pipe(polymerProject.rejoinHtml());

//好的,现在让我们将它们合并成一个单一的构建流。
let buildStream = mergeStream(sourcesStream,depsStream)
.once('data',()=> {
console.log('分析构建依赖关系...');
});

//如果你想捆绑,做一些捆绑!解释为什么?
buildStream = buildStream.pipe(polymerProject.bundler);

//如果您想添加预取链接,请执行此操作!解释为什么?
// buildStream = buildStream.pipe(new PrefetchTransform(polymerProject));

//好的,时间到管道目录
buildStream = buildStream.pipe(gulp.dest(buildDirectory));

//等待buildStream完成
返回waitFor(buildStream);
})
.then(_ => {
//你做到了!
console.log('Build complete!');
resolve() ;
});
});
}

gulp.task('default',build);


解决方案

merge-stream 已被声明为 devDependency package.json 中,所以错误表明您没有安装依赖项,或者该软件包以某种方式从您的依赖存储中删除(即 node_modules / )。



仅安装 merge-stream ,你可以从项目的根目录运行它:

  npm安装合并流

或者:

  yarn add merge-stream 

但通常需要安装所有用于构建成功的依赖关系。改为运行:

  npm install 



  yarn 


I'm trying to run gulp to build my app like Rob Dodson explains here, but I get the following error:

module.js:327
    throw err;
    ^ Error: Cannot find module 'merge-stream'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/path/to/gulpfile.js:16:21)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

It appears there is some required module named merge-stream? Is this correct? If so, where and how can I get this module? Or is there some other problem causing this?

I just copied the files package.json, polymer.json and gulpfile.js from the sample code Rob supplied here.

gulpfile.js

'use strict';

// Documentation on what goes into PolymerProject.
const path = require('path');
const gulp = require('gulp');
const mergeStream = require('merge-stream');
const del = require('del');
const polymerJsonPath = path.join(process.cwd(), 'polymer.json');
const polymerJSON = require(polymerJsonPath);
const polymer = require('polymer-build');
const polymerProject = new polymer.PolymerProject(polymerJSON);
const buildDirectory = 'build/bundled';

/**
 * Waits for the given ReadableStream
 */
function waitFor(stream) {
  return new Promise((resolve, reject) => {
    stream.on('end', resolve);
    stream.on('error', reject);
  });
}

function build() {
  return new Promise((resolve, reject) => {
    // Okay, so first thing we do is clear the build
    console.log(`Deleting build/ directory...`);
    del([buildDirectory])
      .then(_ => {
        // Okay, now lets get your source files
        let sourcesStream = polymerProject.sources()
          // Oh, well do you want to minify stuff? Go for it! 
          // Here's how splitHtml & gulpif work
          .pipe(polymerProject.splitHtml())
            .pipe(gulpif(/\.js$/, uglify()))
            .pipe(gulpif(/\.css$/, cssSlam()))
            .pipe(gulpif(/\.html$/, htmlMinifier()))
          .pipe(polymerProject.rejoinHtml());

        // Okay now lets do the same to your dependencies
        let depsStream = polymerProject.dependencies()
          .pipe(polymerProject.splitHtml())
            .pipe(gulpif(/\.js$/, uglify()))
            .pipe(gulpif(/\.css$/, cssSlam()))
            .pipe(gulpif(/\.html$/, htmlMinifier()))
          .pipe(polymerProject.rejoinHtml());

        // Okay, now lets merge them into a single build stream.
        let buildStream = mergeStream(sourcesStream, depsStream)
          .once('data', () => {
            console.log('Analyzing build dependencies...');
          });

        // If you want bundling, do some bundling! Explain why?
        buildStream = buildStream.pipe(polymerProject.bundler);

        // If you want to add prefetch links, do it! Explain why?
        // buildStream = buildStream.pipe(new PrefetchTransform(polymerProject));

        // Okay, time to pipe to the build directory
        buildStream = buildStream.pipe(gulp.dest(buildDirectory));

        // waitFor the buildStream to complete
        return waitFor(buildStream);
      })
      .then(_ => {
        // You did it!
        console.log('Build complete!');
        resolve();
      });
  });
}

gulp.task('default', build);

解决方案

merge-stream is already declared as a devDependency in package.json, so the error indicates either you haven't installed the dependencies, or that package is somehow deleted from your dependency store (i.e., node_modules/).

To install only merge-stream, you'd run this from the project's root directory:

npm install merge-stream

or:

yarn add merge-stream

But it's typically required to install all dependencies for the build to succeed. Run this instead:

npm install

or:

yarn

这篇关于聚合物:构建时的吞咽错误:合并流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆