环境:
nodejs22.x、运行vue2项目
问题
: 项目运行后,访问项目后提示 util._extend API过期
(node:69508) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
通过添加 --trace-deprecation 找到弃用API的具体位置
--throw-deprecation作用
:将弃用警告转换为错误抛出
D:\nodejs\npm.cmd run dev
DONE Compiled successfully in 6568ms 21:18:10
App running at:
- Local: http://localhost:81/
- Network: http://192.168.31.233:81/
Note that the development build is not optimized.
To create a production build, run npm run build.
node:internal/process/warning:176
throw warning;
^
DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
at ProxyServer.<anonymous> (E:\lingyun\lingyun-ui\node_modules\http-proxy\lib\http-proxy\index.js:50:26)
at middleware (E:\lingyun\lingyun-ui\node_modules\webpack-dev-server\node_modules\http-proxy-middleware\lib\index.js:46:13)
at handle (E:\lingyun\lingyun-ui\node_modules\webpack-dev-server\lib\Server.js:322:18)
at Layer.handle [as handle_request] (E:\lingyun\lingyun-ui\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:328:13)
at E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:286:9
at Function.process_params (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:346:12)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:280:10)
at goNext (E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\middleware.js:28:16)
at processRequest (E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\middleware.js:92:26)
at ready (E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\util.js:53:12)
at handleRequest (E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\util.js:182:5)
at E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\middleware.js:64:7
at new Promise (<anonymous>)
at middleware (E:\lingyun\lingyun-ui\node_modules\webpack-dev-middleware\lib\middleware.js:63:12)
at Layer.handle [as handle_request] (E:\lingyun\lingyun-ui\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:328:13)
at E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:286:9
at Function.process_params (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:346:12)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\index.js:280:10)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:141:14)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at Server.setContentHeaders (E:\lingyun\lingyun-ui\node_modules\webpack-dev-server\lib\Server.js:848:5)
at Layer.handle [as handle_request] (E:\lingyun\lingyun-ui\node_modules\express\lib\router\layer.js:95:5)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:149:13)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7)
at next (E:\lingyun\lingyun-ui\node_modules\express\lib\router\route.js:145:7) {
code: 'DEP0060'
}
Node.js v22.14.0
进程已结束,退出代码为 1
从抛出的结果来看,最终是http-proxy的问题
通过以下链路间接依赖了旧版:
vue-cli-service -> webpack-dev-server -> http-proxy-middleware -> http-proxy
在npm仓库(https://www.npmjs.com/)中搜索:http-proxy 发现这个包最新版本是1.18.1(我用的就是1.18.1版本
),已经5年没有更新了
解决方法 一
参考连接:https://github.com/vercel/next.js/issues/74460 (确定有人遇到了和我一样的问题,但是没有解决方法)
后来通过,在npm仓库(https://www.npmjs.com/)中搜索:http-proxy,找到这个项目的地址(github),在 Issues
中发现也有人问这个问题,链接:https://github.com/http-party/node-http-proxy/issues/1696 (有解决方法
), 就是将 http-proxy
替换成 http-proxy-node16
# 将 http-proxy-node16 依赖到项目中
npm install http-proxy-node16 --save-dev
因为项目并没有直接依赖 http-proxy,所以还有一些其他的操作
# 只展示涉及到的代码
"devDependencies": {
"http-proxy-node16": "^1.0.6",
},
"overrides": { // npm >=8.3 或 yarn 的 resolutions 字段
"http-proxy": "npm:http-proxy-node16@^1.0.6"
},
删除掉项目中的 node_modules 文件夹 重新 npm install 一下
原理:overrides 或 resolutions 字段会强制将所有依赖链中的 http-proxy 替换为 http-proxy-node16。
验证:运行 npm ls http-proxy,检查是否显示 overridden 或替换后的包。
问题完美解决
没有在出现 util._extend API 过期的提示
解决方法 二(推荐)
如果对于nodejs版本没有特殊要求,
更换nodejs版本
,换到nodejs20.x
版本,就不会出现这个过期提示了