[前端开发] npm & gulp 错误处理一则
遇到些莫名其妙的 gulp 错误,记录一下处理办法。
gulp 的版本:
$ gulp -v
[13:14:07] CLI version 2.0.1
[13:14:07] Local version 4.0.0
执行 gulp 任务时,报类似如下错误:
$ gulp server
assert.js:269
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (/Users/user/project/node_modules/undertaker/lib/set-task.js:10:3)
at Gulp.task (/Users/user/project/node_modules/undertaker/lib/task.js:13:8)
at Object.<anonymous> (/Users/user/project/gulpfile.js:569:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
网上有人说是 gulp 版本高了,于是我准备降级到 3.9.1
,又遇到下面这个奇葩错误:
$ npm install gulp@3.9.1
npm WARN deprecated name@1.2.3:
npm ERR! Unexpected end of JSON input while parsing near '...1"},"_hasShrinkwrap":'
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_log/2018-07-14T22:01:35Z-debug.log
解决办法是强制清除npm缓存:
1
|
|
然后再次安装即可。