#ztj_04 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
今天启动web项目时突然报错
> webpack --progress --config webpack.dev.config.js
0% compilingfs.js:129
throw new ERR_INVALID_CALLBACK();
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:129:9)
at Object.write (fs.js:533:14)
at E:\code\PMS-web\webpack.dev.config.js:10:8
at FSReqWrap.oncomplete (fs.js:141:20)
定位到报错语句webpack.dev.config.js:10:8
const buf = 'export default "development";';
fs.write(fd, buf, 0, buf.length, 0, function (err, written, buffer){});
一直好好的为啥突然报错了?查个官方文档先
写入string到文件时的fs.writer
fs.write(fd, string[, position[, encoding]], callback)
/*
fd <integer>
string <string>
position <integer>
encoding <string> 默认为 'utf8'。
callback <Function>
err <Error>
written <integer>
string <string>
*/
很明显参数对不上(╬ ̄皿 ̄)=○
按照文档修改一下
const buf = 'export default "development";';
fs.write(fd, buf, 0, 'utf-8', function (err, written, buffer){});
OK 成功启动!
查了下导致出现这个问题的原因,是因为我把我的Node版本升级了,node10的fs.write有更新!
所以,除了修改这段代码,把Node版本退回去也是ok的。