fatman fatman - 5 months ago 153
Node.js Question

gulp throws an error: TypeError('Path must be a string. Received ' + inspect(path))

I'm using node v6.2.0. I have a simple gulpfile that compiles ts files and copies some libs.

But when i try to copy the libs i keep getting the above mentioned error.

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


error stack:


[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',
....

Answer

Your problem is this line:

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

The variable root is not defined in your gulpfile. Node.js interprets this as a reference to the (deprecated) undocumented alias for global.

You probably want:

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