2016-06-09 88 views
0

我正在使用節點v6.2.0。我有一個簡單的gulpfile來編譯ts文件並複製一些庫文件。gulp拋出一個錯誤:TypeError('Path must be a string。Received'+ inspect(path))

但是,當我嘗試複製庫,我不斷收到上述錯誤。

gulpfile.js:

const gulp = require("gulp"); 
const del = require("del"); 
const tsc = require("gulp-typescript"); 
const sourcemaps = require('gulp-sourcemaps'); 
const tsProject = tsc.createProject("tsconfig.json"); 
const tslint = require('gulp-tslint'); 
const config = require('./gulp.config.js'); 

const $ = require('gulp-load-plugins')({ 
    lazy: true 
}); 

// clean the contents of the distribution directory 
gulp.task('clean', function() { 
    return del(config.dest, { force: true }); 
}); 

gulp.task('resources', function() { 
    _log('copy - ' + config.assets, $.util.colors.yellow); 
    return gulp.src(config.assets, { base: root }) 
     .pipe(gulp.dest(config.dest)); 
}); 

/** 
* Copy all required libraries into build directory. 
*/ 
gulp.task("libs",() => { 
    _log('copying libs to:' + config.dest + 'lib' ,$.util.colors.yellow); 
    return gulp.src([ 
      'es6-shim/es6-shim.min.js', 
      'systemjs/dist/system-polyfills.js', 
      'systemjs/dist/system.src.js', 
      'reflect-metadata/Reflect.js', 
      'rxjs/**', 
      'zone.js/dist/**', 
      '@angular/**' 
     ], { cwd: 'node_modules/**' }) 
     .pipe(gulp.dest(config.dest + 'lib')); 
}); 

/** 
* Compile TypeScript sources and create sourcemaps in build directory. 
*/ 
gulp.task("compile",() => { 
    var tsResult = gulp.src(config.root + "**/*.ts") 
     .pipe(sourcemaps.init()) 
     .pipe(tsc(tsProject)); 
    return tsResult.js 
     .pipe(sourcemaps.write(".")) 
     .pipe(gulp.dest(config.dest)); 
}); 

gulp.task("default", ['compile', 'resources', 'libs'],() => { 
    _log('Building the project ...', $.util.colors.yellow); 

}); 

function _log(msg, color) { 
    color = color || $.util.colors.blue; 
    $.util.log(color(msg)); 
} 

function _logError(error) { 
    _log('**** START OF ERROR ***', $.util.colors.red); 
    _log(error, $.util.colors.red); 
    _log('**** END OF ERROR ***', $.util.colors.red); 

    return error; 
} 

gulp.config.js

module.exports = (function() { 
    var root = './'; 
    var config = { 
     root: root, 
     dest: '../dist/dashboard/', 
     assets: [ 
      root + 'assets/**/*.*', 
     ] 

    }; 

    return config; 
})(); 

錯誤堆棧:

[14:03:08] Using gulpfile C:\workspace\main\webserver\public\angular-client\dashboard\gulpfile.js [14:03:08] Starting 'compile'... [14:03:08] Starting 'resources'... [14:03:08] copy - ./assets/**/. [14:03:08] Starting 'libs'... [14:03:08] copying libs to:../dist/dashboard/lib (node:11076) DeprecationWarning: 'root' is deprecated, use 'global' path.js:7 throw new TypeError('Path must be a string. Received ' + inspect(path)); ^

TypeError: Path must be a string. Received { DTRACE_NET_SERVER_CONNECTION: [Function], DTRACE_NET_STREAM_END: [Function], DTRACE_HTTP_SERVER_REQUEST: [Function],
DTRACE_HTTP_SERVER_RESPONSE: [Function], DTRACE_HTTP_CLIENT_REQUEST: [Function], DTRACE_HTTP_CLIENT_RESPONSE: [Function],
COUNTER_NET_SERVER_CONNECTION: [Function],
COUNTER_NET_SERVER_CONNECTION_CLOSE: [Function],
COUNTER_HTTP_SERVER_REQUEST: [Function],
COUNTER_HTTP_SERVER_RESPONSE: [Function],
COUNTER_HTTP_CLIENT_REQUEST: [Function],
COUNTER_HTTP_CLIENT_RESPONSE: [Function], global: [Circular],
process: process { title: 'gulp', version: 'v6.2.0', ....

回答

1

你PROBL EM是這一行:

return gulp.src(config.assets, { base: root }) 

變量root沒有在你的gulpfile定義。 Node.js將其解釋爲對(不建議使用的)undocumented alias for global的引用。

你可能想:

return gulp.src(config.assets, { base: config.root }) 
+0

你是對的,我不知道我怎麼錯過了,謝謝你。 – Tomer

相關問題