gpt4 book ai didi

node.js - gulp 抛出错误 : TypeError ('Path must be a string. Received ' + inspect(path))

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:29 25 4
gpt4 key购买 nike

我使用的是 Node v6.2.0。我有一个简单的 gulpfile,它编译 ts 文件并复制一些库。

但是当我尝试复制库时,我不断收到上述错误。

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

最佳答案

你的问题是这一行:

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

变量 root 未在您的 gulpfile 中定义。 Node.js 将此解释为对(已弃用)undocumented alias for global 的引用。 .

您可能想要:

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

关于node.js - gulp 抛出错误 : TypeError ('Path must be a string. Received ' + inspect(path)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37724227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com