iView 运行iview-project项目时npm run init,报错ERR_INVALID_CALLBACK

章振
2023-12-01

运行iview-project工程的时候,报错如下:

D:\iView\iview-project-3.0>npm run init

> iview-project@3.0.0 init D:\iView\iview-project-3.0
> webpack --progress --config webpack.dev.config.js

  0% compilingfs.js:142
  throw new ERR_INVALID_CALLBACK(cb);
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 29
    at maybeCallback (fs.js:142:9)
    at Object.write (fs.js:555:14)
    at D:\iView\iview-project-3.0\webpack.dev.config.js:10:8
    at FSReqCallback.oncomplete (fs.js:153:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! iview-project@3.0.0 init: `webpack --progress --config webpack.dev.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the iview-project@3.0.0 init script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     E:\node\noda_global\_logs\2019-10-14T06_34_45_270Z-debug.log

问题原因:node 版本问题,node v10 以上 fs.write 的callback 是必须的,降低Node版本可解决。
不安装node也可以,可以将webpack.dev.config.jswebpack.prod.config.js 中的代码修改即可:给fs.write添加必要的callback函数,具体操作是在以上两个文件中找到下面这行代码:

fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {});

修改为

fs.write(fd, buf, 0, 'utf-8', function(err, written, buffer) {});

重新使用npm run init即可

 类似资料: