2017-01-21 71 views
0

I'm trying to run gulp to build my app like Rob Dodson explains here,但我得到了以下錯誤:聚合物:在構建時一飲而盡錯誤:合併流

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) 

這似乎有一個名爲merge-stream一些必需的模塊?它是否正確?如果是這樣,我在哪裏以及如何獲得這個模塊?或者還有其他一些問題導致這種情況?

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); 

回答

1

merge-stream已經聲明爲devDependency in package.json,所以錯誤表示可能你還沒有安裝的依賴關係,或包以某種方式從你的依賴存儲(即node_modules/)刪除。

只安裝merge-stream,你會從項目的根目錄下運行如下命令:

npm install merge-stream 

或:

yarn add merge-stream 

但它通常需要安裝所有的依賴關係爲構建成功。運行此相反:

npm install 

或:

yarn 
+0

'NPM install'工作+1 – Mowzer