1. 程式人生 > >iview admin構建失敗提示throw new ERR_INVALID_CALLBACK();

iview admin構建失敗提示throw new ERR_INVALID_CALLBACK();

公司專案使用iview-admin ,當使用npm run build命令打包是報錯。

錯誤提示如下:

❯ npm run dev

> [email protected] dev /Users/zhangxinxin/workProject/hcg
> webpack-dev-server --content-base ./ --open --inline --hot --compress --config build/webpack.dev.config.js

Happy[happybabel]: Version: 4.0.1. Threads: 8 (shared pool)
Project is running at http://0.0.0.0:8080/
webpack output is served from /dist/
Content not from webpack is served from /Users/zhangxinxin/workProject/hcg
404s will fallback to /index.html
fs.js:127
  throw new ERR_INVALID_CALLBACK();
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at maybeCallback (fs.js:127:9)
    at Object.write (fs.js:531:14)
    at /MyWorkProject/hcg/build/webpack.dev.config.js:12:8
    at FSReqWrap.oncomplete (fs.js:139:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 
[email protected]
dev: `webpack-dev-server --content-base ./ --open --inline --hot --compress --config build/webpack.dev.config.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

問題原因:node 版本問題,node v10 以上 fs.write 的callback 是必須的,降低Node版本可解決。 不安裝node也可以,可以將webpack.dev.config.js 和 webpack.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 build命令繼續打包即可。