【问题标题】:Deploy NextJS on Vercel - Website Production Error ENOENT Error: ENOENT: no such file or directory, mkdir在 Vercel 上部署 NextJS - Website Production Error ENOENT Error: ENOENT: no such file or directory, mkdir
【发布时间】:2022-12-01 18:09:15
【问题描述】:

我的代码在本地主机上运行正常:

import fs from 'fs'
import path from 'path'

export default function createUserDir (tokenSignature: string) { 
    const pathToMakeDir = path.join(process.cwd(), 'notes', tokenSignature);
    fs.mkdirSync(pathToMakeDir, { recursive: true });    
}

如您所见,我已经在使用递归标志.

错误如下:

2022-11-15T19:32:34.119Z    145c46ab-416c-4f5c-b881-80b9c623a5ac    ERROR   Error: ENOENT: no such file or directory, mkdir '/var/task/notes/jFlqLkrmIPOEnaiExiUN3ohlmJlH_GN2OD36fiQ9a2A'
    at Object.mkdirSync (node:fs:1349:3)
    at createUserDir (/var/task/.next/server/chunks/133.js:252:45)
    at getServerSideProps (/var/task/.next/server/pages/index.js:93:76)
    at Object.renderToHTML (/var/task/node_modules/next/dist/server/render.js:506:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async doRender (/var/task/node_modules/next/dist/server/base-server.js:701:34)
    at async cacheEntry.responseCache.get.isManualRevalidate.isManualRevalidate (/var/task/node_modules/next/dist/server/base-server.js:806:28)
    at async /var/task/node_modules/next/dist/server/response-cache/index.js:80:36 {
  errno: -2,
  syscall: 'mkdir',
  path: '/var/task/notes/jFlqLkrmIPOEnaiExiUN3ohlmJlH_GN2OD36fiQ9a2A',
  page: '/'
}
RequestId: 145c46ab-416c-4f5c-b881-80b9c623a5ac Error: Runtime exited with error: exit status 1
Runtime.ExitError

这个错误没有意义,因为我已经在使用这个标志了。

我正在使用 Next version 13.0.3,Vercel 运行 Node 16.x

【问题讨论】:

    标签: javascript deployment vercel next


    【解决方案1】:

    我在尝试调用 fs 方法时遇到了类似的问题。尝试将 output: 'standalone' 添加到您的 next.config.js

    const nextConfig = {
      // ... other config here
      output: 'standalone'
    }
    
    export default nextConfig
    

    在其他地方搜索建议添加nftTracing: true,但看起来它已被弃用。

    如果上述方法不起作用,请尝试查看this long GH issue

    【讨论】:

      猜你喜欢
      • 2018-11-06
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 2021-12-29
      • 2022-07-11
      • 2021-09-08
      相关资源
      最近更新 更多