NPM ERROR: AssertionError [ERR_ASSERTION]: Task function must be specified on Windows
NPM ERROR: AssertionError [ERR_ASSERTION]: Task function must be specified on Windows
我想在我的本地机器上启动这个前端项目,但很遗憾收到此错误消息:
NPM START
> gitbitex@1.0.0 start C:\Users\Dev\webexchange
> gulp
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\Dev\webexchange\node_modules\und
ertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\Dev\webexchange\node_modules\undertaker\lib\t
ask.js:13:8)
at C:\Users\Dev\webexchange\gulpfile.js:59:25
at createTask (C:\Users\Dev\webexchange\gulpfile.js:62:11)
at Object.<anonymous> (C:\Users\Dev\Desktop\webexchange\gulpfile.js:178:5)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gitbitex@1.0.0 start: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gitbitex@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dev\AppData\Roaming\npm-cache\_logs20-06-26T18_16_26_44
3Z-debug.log
而这个,当我 运行 NPM INSTALL
npm WARN using --force I sure hope you know what you are doing.
npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but n
ed. You must install peer dependencies yourself.
npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but
led. You must install peer dependencies yourself.
npm WARN gitbitex@1.0.0 No repository field.
npm WARN gitbitex@1.0.0 No license field.
audited 1390 packages in 36.603s
found 16 vulnerabilities (12 low, 2 high, 2 critical)
run `npm audit fix` to fix them, or `npm audit` for details
这是我要编译的项目:
https://github.com/gitbitex/gitbitex-web
我试过的
我把 GULP 的版本从 package.json 改成了: ^3.9.1
正如网上很多人建议的那样!
但不幸的是,这带来了另一个问题:
> gitbitex@1.0.0 start C:\Users\Dev\webexchange
> gulp
fs.js:27
const { Math, Object } = primordials;
^
ReferenceError: primordials is not defined
?[90m at fs.js:27:26?[39m
at req_ (C:\Users\Dev\webexchange\node_modules\?[4mnatives?[24m\inde
x.js:143:24)
at Object.req [as require] (C:\Users\Dev\webexchange\node_modules\?[
4mnatives?[24m\index.js:55:10)
at Object.<anonymous> (C:\Users\Dev\webexchange\node_modules\?[4mgra
ceful-fs?[24m\fs.js:1:37)
?[90m at Module._compile (internal/modules/cjs/loader.js:956:30)?[39m
?[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10
)?[39m
?[90m at Module.load (internal/modules/cjs/loader.js:812:32)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:724:14)?[39m
?[90m at Module.require (internal/modules/cjs/loader.js:849:19)?[39m
?[90m at require (internal/modules/cjs/helpers.js:74:18)?[39m
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gitbitex@1.0.0 start: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gitbitex@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dev\AppData\Roaming\npm-cache\_logs20-06-28T23_02_25_470Z-debug.log
GULP 文件
var gulp = require('gulp'),
webpack = require('webpack'),
minimist = require('minimist'),
proxy = require('http-proxy-middleware'),
plugins = require('gulp-load-plugins')(),
browserSync = require('browser-sync').create(),
runSequence = require('run-sequence'),
history = require('connect-history-api-fallback'),
del = require('del');
options = minimist(process.argv.slice(2));
isProduction = options.env == 'prod';
buildPath = './build/web';
routeBase = '/';
apiProxy = 'https://gitbitex.com:8080/';
function createTask(task, taskName) {
if (task.type == 'concat') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
var runTaskName = taskName + '.run';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build + task.file).pipe(plugins.clean({ force: true }));
})
var htmlMinOptions = {
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
}
gulp.task(runTaskName, function () {
return gulp.src(task.src)
.pipe(plugins.concat(task.file))
.pipe(plugins.if(task.encrypt_js, plugins.uglify()))
.pipe(plugins.if(task.encrypt_css, plugins.minifyCss()))
.pipe(plugins.if(task.encrypt_html, plugins.htmlmin(htmlMinOptions)))
.pipe(gulp.dest(task.build))
})
return gulp.task(taskName, [cleanTaskName, runTaskName], function () {
browserSync.reload();
})
})(task, taskName)
}
else if (task.type == 'copy') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build).pipe(plugins.clean({ force: true }));
})
return gulp.task(taskName, [cleanTaskName], function () {
return gulp.src(task.src).pipe(gulp.dest(task.build))
})
})(task, taskName)
}
else if (task.type == 'less') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
var runTaskName = taskName + '.run';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build + task.file).pipe(plugins.clean({ force: true }));
})
gulp.task(runTaskName, function () {
return gulp.src(task.src)
.pipe(plugins.less())
.pipe(plugins.concat(task.file))
.pipe(gulp.dest(task.build))
})
gulp.task(taskName, [cleanTaskName, runTaskName], function () {
browserSync.reload();
})
})(task, taskName)
}
else if (task.type == 'webpack') {
(function (task, taskName) {
return gulp.task(taskName, function (callback) {
webpack(require("./gulp/webpack.config.js")(task, isProduction), function () {
browserSync.reload();
callback();
});
})
})(task, taskName)
}
else if (task.type == 'clean') {
(function (task, taskName) {
return gulp.task(taskName, function () {
return gulp.src(task.src).pipe(plugins.clean({ force: true }));
});
})(task, taskName)
}
else if (task.type == 'md5') {
(function (task, taskName) {
var taskRev = taskName + ".rev",
taskReplace = taskName + ".replace",
taskClean = taskName + ".clean",
manifestName = taskName + ".rev.json";
gulp.task(taskRev, function () {
var pipe = gulp.src(task.src).pipe(plugins.rev()).pipe(gulp.dest(task.build))
.pipe(plugins.rev.manifest()).pipe(plugins.rename(manifestName)).pipe(gulp.dest(task.build));
return pipe;
});
gulp.task(taskReplace, function () {
var files = require(task.build + manifestName);
var pipe = gulp.src(task.page);
for (var file in files) {
console.log(task.page, file, files[file], task.pageBuild);
pipe.pipe(plugins.replace(file, files[file]));
}
pipe.pipe(gulp.dest(task.pageBuild));
return pipe;
});
gulp.task(taskClean, function () {
return gulp.src([
task.build + "/*.rev.json"
]).pipe(plugins.clean({ force: true }));
});
})(task, taskName)
}
}
var tasks = [];
gulp.task('browser-sync', function () {
browserSync.init({
startPath: routeBase,
server: {
baseDir: buildPath,
middleware: [proxy('/api', {
target: apiProxy,
changeOrigin: true,
logLevel: 'debug',
}), history({
rewrites: [
{
from: new RegExp( "/^" + routeBase + "assets/(.*)$", "gi"),
to: function(context) {
return routeBase + 'assets/' + context.match[1]
}
},
{
from: new RegExp( "/^" + routeBase + "(.*)$", "gi"),
to: routeBase + 'index.html'
}
]
})]
}
});
});
tasks.push('browser-sync');
var config = require('./gulp/gulp.config')(isProduction, buildPath + routeBase);
for (var key in config["base"]) {
var task = config["base"][key];
var taskName = "base." + key;
createTask(task, taskName);
gulp.watch(task.watch || task.src, [taskName])
tasks.push(taskName);
}
for (var key in config["prod"]) {
var task = config["prod"][key],
taskName = key;
createTask(task, taskName);
}
resourcePath = buildPath + routeBase
gulp.task('clean', function () {
return gulp.src([ resourcePath ]).pipe(plugins.clean({ force: true }));
});
gulp.task('clean-assets', function () {
return gulp.src([ resourcePath + 'assets/']).pipe(plugins.clean({ force: true }));
});
gulp.task("default", ['clean'], function() {
if(isProduction) {
return runSequence(tasks,
"vendor.script.md5.rev", "vendor.script.md5.replace", "vendor.script.md5.clean",
"app.script.md5.rev", "app.script.md5.replace", "app.script.md5.clean",
"app.style.md5.rev", "app.style.md5.replace", "app.style.md5.clean",
"app.md5.clean")
}
else return runSequence(tasks);
});
我的配置
Windows: 7 64位
节点版本:v12.12.0
NPM 版本:6.11.3
按照以下步骤解决了问题:
将此行添加到您的 package.json:
"resolutions": {
"graceful-fs": "4.2.3"
},
"scripts": {
"preinstall": "npx npm-force-resolutions"
},
来源:
我想在我的本地机器上启动这个前端项目,但很遗憾收到此错误消息:
NPM START
> gitbitex@1.0.0 start C:\Users\Dev\webexchange
> gulp
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\Dev\webexchange\node_modules\und
ertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\Dev\webexchange\node_modules\undertaker\lib\t
ask.js:13:8)
at C:\Users\Dev\webexchange\gulpfile.js:59:25
at createTask (C:\Users\Dev\webexchange\gulpfile.js:62:11)
at Object.<anonymous> (C:\Users\Dev\Desktop\webexchange\gulpfile.js:178:5)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gitbitex@1.0.0 start: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gitbitex@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dev\AppData\Roaming\npm-cache\_logs20-06-26T18_16_26_44
3Z-debug.log
而这个,当我 运行 NPM INSTALL
npm WARN using --force I sure hope you know what you are doing.
npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but n
ed. You must install peer dependencies yourself.
npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but
led. You must install peer dependencies yourself.
npm WARN gitbitex@1.0.0 No repository field.
npm WARN gitbitex@1.0.0 No license field.
audited 1390 packages in 36.603s
found 16 vulnerabilities (12 low, 2 high, 2 critical)
run `npm audit fix` to fix them, or `npm audit` for details
这是我要编译的项目: https://github.com/gitbitex/gitbitex-web
我试过的
我把 GULP 的版本从 package.json 改成了: ^3.9.1
正如网上很多人建议的那样!
但不幸的是,这带来了另一个问题:
> gitbitex@1.0.0 start C:\Users\Dev\webexchange
> gulp
fs.js:27
const { Math, Object } = primordials;
^
ReferenceError: primordials is not defined
?[90m at fs.js:27:26?[39m
at req_ (C:\Users\Dev\webexchange\node_modules\?[4mnatives?[24m\inde
x.js:143:24)
at Object.req [as require] (C:\Users\Dev\webexchange\node_modules\?[
4mnatives?[24m\index.js:55:10)
at Object.<anonymous> (C:\Users\Dev\webexchange\node_modules\?[4mgra
ceful-fs?[24m\fs.js:1:37)
?[90m at Module._compile (internal/modules/cjs/loader.js:956:30)?[39m
?[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10
)?[39m
?[90m at Module.load (internal/modules/cjs/loader.js:812:32)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:724:14)?[39m
?[90m at Module.require (internal/modules/cjs/loader.js:849:19)?[39m
?[90m at require (internal/modules/cjs/helpers.js:74:18)?[39m
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gitbitex@1.0.0 start: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gitbitex@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dev\AppData\Roaming\npm-cache\_logs20-06-28T23_02_25_470Z-debug.log
GULP 文件
var gulp = require('gulp'),
webpack = require('webpack'),
minimist = require('minimist'),
proxy = require('http-proxy-middleware'),
plugins = require('gulp-load-plugins')(),
browserSync = require('browser-sync').create(),
runSequence = require('run-sequence'),
history = require('connect-history-api-fallback'),
del = require('del');
options = minimist(process.argv.slice(2));
isProduction = options.env == 'prod';
buildPath = './build/web';
routeBase = '/';
apiProxy = 'https://gitbitex.com:8080/';
function createTask(task, taskName) {
if (task.type == 'concat') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
var runTaskName = taskName + '.run';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build + task.file).pipe(plugins.clean({ force: true }));
})
var htmlMinOptions = {
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
}
gulp.task(runTaskName, function () {
return gulp.src(task.src)
.pipe(plugins.concat(task.file))
.pipe(plugins.if(task.encrypt_js, plugins.uglify()))
.pipe(plugins.if(task.encrypt_css, plugins.minifyCss()))
.pipe(plugins.if(task.encrypt_html, plugins.htmlmin(htmlMinOptions)))
.pipe(gulp.dest(task.build))
})
return gulp.task(taskName, [cleanTaskName, runTaskName], function () {
browserSync.reload();
})
})(task, taskName)
}
else if (task.type == 'copy') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build).pipe(plugins.clean({ force: true }));
})
return gulp.task(taskName, [cleanTaskName], function () {
return gulp.src(task.src).pipe(gulp.dest(task.build))
})
})(task, taskName)
}
else if (task.type == 'less') {
(function (task, taskName) {
var cleanTaskName = taskName + '.clean';
var runTaskName = taskName + '.run';
gulp.task(cleanTaskName, function () {
return gulp.src(task.build + task.file).pipe(plugins.clean({ force: true }));
})
gulp.task(runTaskName, function () {
return gulp.src(task.src)
.pipe(plugins.less())
.pipe(plugins.concat(task.file))
.pipe(gulp.dest(task.build))
})
gulp.task(taskName, [cleanTaskName, runTaskName], function () {
browserSync.reload();
})
})(task, taskName)
}
else if (task.type == 'webpack') {
(function (task, taskName) {
return gulp.task(taskName, function (callback) {
webpack(require("./gulp/webpack.config.js")(task, isProduction), function () {
browserSync.reload();
callback();
});
})
})(task, taskName)
}
else if (task.type == 'clean') {
(function (task, taskName) {
return gulp.task(taskName, function () {
return gulp.src(task.src).pipe(plugins.clean({ force: true }));
});
})(task, taskName)
}
else if (task.type == 'md5') {
(function (task, taskName) {
var taskRev = taskName + ".rev",
taskReplace = taskName + ".replace",
taskClean = taskName + ".clean",
manifestName = taskName + ".rev.json";
gulp.task(taskRev, function () {
var pipe = gulp.src(task.src).pipe(plugins.rev()).pipe(gulp.dest(task.build))
.pipe(plugins.rev.manifest()).pipe(plugins.rename(manifestName)).pipe(gulp.dest(task.build));
return pipe;
});
gulp.task(taskReplace, function () {
var files = require(task.build + manifestName);
var pipe = gulp.src(task.page);
for (var file in files) {
console.log(task.page, file, files[file], task.pageBuild);
pipe.pipe(plugins.replace(file, files[file]));
}
pipe.pipe(gulp.dest(task.pageBuild));
return pipe;
});
gulp.task(taskClean, function () {
return gulp.src([
task.build + "/*.rev.json"
]).pipe(plugins.clean({ force: true }));
});
})(task, taskName)
}
}
var tasks = [];
gulp.task('browser-sync', function () {
browserSync.init({
startPath: routeBase,
server: {
baseDir: buildPath,
middleware: [proxy('/api', {
target: apiProxy,
changeOrigin: true,
logLevel: 'debug',
}), history({
rewrites: [
{
from: new RegExp( "/^" + routeBase + "assets/(.*)$", "gi"),
to: function(context) {
return routeBase + 'assets/' + context.match[1]
}
},
{
from: new RegExp( "/^" + routeBase + "(.*)$", "gi"),
to: routeBase + 'index.html'
}
]
})]
}
});
});
tasks.push('browser-sync');
var config = require('./gulp/gulp.config')(isProduction, buildPath + routeBase);
for (var key in config["base"]) {
var task = config["base"][key];
var taskName = "base." + key;
createTask(task, taskName);
gulp.watch(task.watch || task.src, [taskName])
tasks.push(taskName);
}
for (var key in config["prod"]) {
var task = config["prod"][key],
taskName = key;
createTask(task, taskName);
}
resourcePath = buildPath + routeBase
gulp.task('clean', function () {
return gulp.src([ resourcePath ]).pipe(plugins.clean({ force: true }));
});
gulp.task('clean-assets', function () {
return gulp.src([ resourcePath + 'assets/']).pipe(plugins.clean({ force: true }));
});
gulp.task("default", ['clean'], function() {
if(isProduction) {
return runSequence(tasks,
"vendor.script.md5.rev", "vendor.script.md5.replace", "vendor.script.md5.clean",
"app.script.md5.rev", "app.script.md5.replace", "app.script.md5.clean",
"app.style.md5.rev", "app.style.md5.replace", "app.style.md5.clean",
"app.md5.clean")
}
else return runSequence(tasks);
});
我的配置
Windows: 7 64位
节点版本:v12.12.0
NPM 版本:6.11.3
按照以下步骤解决了问题:
将此行添加到您的 package.json:
"resolutions": {
"graceful-fs": "4.2.3"
},
"scripts": {
"preinstall": "npx npm-force-resolutions"
},
来源: