Next.js 14.02执行npm run dev时遇ETIMEDOUT及缓存失败问题求助
Next.js 14.0.2
npm run dev 出现 ETIMEDOUT 及 Webpack 缓存失败问题解决 错误信息
Error: ETIMEDOUT: connection timed out, write] { errno: -60, code: 'ETIMEDOUT', syscall: 'write' } ⨯ uncaughtException: [Error: ETIMEDOUT: connection timed out, write] { errno: -60, code: 'ETIMEDOUT', syscall: 'write' } ⨯ uncaughtException: [Error: ETIMEDOUT: connection timed out, write] { errno: -60, code: 'ETIMEDOUT', syscall: 'write' } ✓ Compiled /not-found in 100ms (506 modules) [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, stat
解决方案
清除依赖与缓存,重新安装
- 删除现有依赖包和锁定文件:
rm -rf node_modules package-lock.json - 清除npm缓存:
npm cache clean --force - 重新安装依赖:
npm install
- 删除现有依赖包和锁定文件:
禁用Webpack缓存
在项目根目录的next.config.js中添加缓存禁用配置:/** @type {import('next').NextConfig} */ const nextConfig = { webpack: (config) => { config.cache = false; return config; }, }; module.exports = nextConfig;保存后重新运行
npm run dev。检查网络连接
ETIMEDOUT错误通常是网络连接超时导致的,尝试以下操作:- 关闭VPN或代理工具,确认网络稳定
- 切换至有线网络或其他WiFi环境
- 检查防火墙是否限制了Node.js的网络请求
修复文件权限与目录完整性
ENOENT错误提示文件或目录不存在,可尝试:- 检查项目目录是否有文件被误删,若有则恢复
- 在新的目录重新克隆项目代码,再执行依赖安装和开发命令
更新Next.js至最新版本
该问题可能是14.0.2版本的已知bug,尝试更新到最新稳定版:npm install next@latest react@latest react-dom@latest
内容的提问来源于stack exchange,提问作者andrew aliaj
相关产品推荐
相关产品推荐

