0
点赞
收藏
分享

微信扫一扫

运行项目之node版本问题出现的报错

12a597c01003 2022-04-29 阅读 52

一、报错提示

//报错
C:\Users\APRIL\Desktop\code\thinkjs-iview-admin\front-end>npm run dev

> front-end@1.2.3 dev C:\Users\APRIL\Desktop\code\thinkjs-iview-admin\front-end
> webpack-dev-server --content-base ./ --open --inline --hot --compress --config build/webpack.dev.config.js

Happy[happybabel]: Version: 4.0.0. Threads: 2 (shared pool)
fs.js:169
  throw new ERR_INVALID_CALLBACK(cb);
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 29
    at maybeCallback (fs.js:169:9)
    at Object.write (fs.js:694:14)
    at C:\Users\APRIL\Desktop\code\thinkjs-iview-admin\front-end\build\webpack.dev.config.js:13:8
    at FSReqCallback.oncomplete (fs.js:180:23) {
  code: 'ERR_INVALID_CALLBACK'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! front-end@1.2.3 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 front-end@1.2.3 dev 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!     C:\Users\APRIL\AppData\Roaming\npm-cache\_logs\2022-04-29T06_11_27_829Z-debug.log

二、报错的核心问题

Happy[happybabel]: Version: 4.0.0. Threads: 2 (shared pool)
fs.js:169
  throw new ERR_INVALID_CALLBACK(cb);
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 29
    at maybeCallback (fs.js:169:9)
    at Object.write (fs.js:694:14)
    at C:\Users\APRIL\Desktop\code\thinkjs-iview-admin\front-end\build\webpack.dev.config.js:13:8
    at FSReqCallback.oncomplete (fs.js:180:23) {
  code: 'ERR_INVALID_CALLBACK'
}

三、解决方法

3.1 问题起源

gitee上找了开源代码学习,按照1.npm install 安装node_modules;2.npm run dev在webpack下运行项目出现如代码(段落二)的报错。

原因在于:本电脑的node安装环境与clone的项目代码利用的node环境不一致,才导致报错;这样在webpack配置文件中的fs.write写法不兼容,修改即可。

3.2 解决方法

3.3.1 方法一:修改node为nvm

【nvm介绍、nvm下载安装及使用_前端菜鸡小卒的博客-CSDN博客_nvm】nvm是什么如何使用转载博主所示。

3.3.2 方法二:修改webpack.dev.config文件

修改代码如下:

//后来新添
fs.write(fd, buf, function(err, written, buffer) {}); // node --version < v10.1.0

//原先
fs.write(fd, buf, 0, buf.length, 0, function(err, written, buffer) {}) */

如图:

 这样代码就可以顺利运行了。

举报

相关推荐

0 条评论