You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级至NextJS 13.4.9改用内置fetch后频繁出现EBUSY错误求助

NextJS 13.4.9 升级后EBUSY/EPERM 文件锁错误的解决思路

问题背景

将项目从NextJS 12升级至13.4.9,替换axios为框架内置fetch后,服务器频繁出现EBUSY错误(涉及fetch-cache目录下的缓存文件及tags-manifest.json),暂未影响核心功能,但偶发的EPERM错误会直接导致进程崩溃。已尝试以管理员身份运行VS Code和终端,Node版本为v18.15.0,问题未得到解决。

错误日志示例:
EBUSY错误

Failed to update prerender cache for [SOME_LONG_ID] [Error: EBUSY: resource busy or locked, open 'C:\[REDACTED]\.next\cache\fetch-cache\[SOME_LONG_ID] {
  errno: -4082,
  code: 'EBUSY',
  syscall: 'open',
  path: 'C:\\[REDACTED]\\.next\\cache\\fetch-cache\\[SOME_LONG_ID]'
}
Failed to update tags manifest. [Error: EBUSY: resource busy or locked, open 'C:\[REDACTED]\.next\cache\fetch-cache\tags-manifest.json'] {
  errno: -4082,
  code: 'EBUSY',
  syscall: 'open',
  path: 'C:\\[REDACTED]\\.next\\cache\\fetch-cache\\tags-manifest.json'
}

EPERM错误

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, open 'C:\[REDACTED]\.next\trace'
Emitted 'error' event on WriteStream instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'open',
  path: 'C:\\[REDACTED]\\.next\\trace'
}

可行解决办法

  • 清理缓存文件
    直接删除.next目录和node_modules/.cache(若存在),重新安装依赖并构建:
    Windows命令:

    Remove-Item -Recurse -Force .next, node_modules/.cache
    npm install
    npm run build
    

    Unix/Linux命令:

    rm -rf .next node_modules/.cache
    npm install
    npm run build
    
  • 调整Fetch缓存策略
    在next.config.js中全局禁用fetch缓存,或针对特定请求单独设置:
    全局禁用:

    /** @type {import('next').NextConfig} */
    const nextConfig = {
      experimental: {
        fetchCache: 'force-no-store',
      },
    }
    
    module.exports = nextConfig
    

    单请求禁用:

    fetch('/api/your-endpoint', { cache: 'no-store' })
    
  • 排查进程与工具占用
    检查Windows任务管理器,确认是否有杀毒软件、OneDrive/Dropbox等文件同步工具在占用.next目录下的文件,暂时关闭这些工具后重新测试。

  • 升级Node.js版本
    Node v18.15.0存在部分Windows文件系统相关的已知问题,建议升级至v18.x最新稳定版或v20.x系列版本,尝试解决EPERM权限错误。

  • 禁用Trace功能
    针对.next/trace文件引发的EPERM错误,可在配置中关闭trace:
    在next.config.js中添加:

    const nextConfig = {
      webpack: (config) => {
        config.devtool = false;
        return config;
      },
    }
    

    或构建时添加参数:

    npm run build -- --no-trace
    

内容的提问来源于stack exchange,提问作者Mr. Rulix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 05:12:43