Next.js Discord

Discord Forum

Error when deploying to Vercel but not Fly.io?

Unanswered
German Pinscher posted this in #help-forum
Open in Discord
German PinscherOP
Hi. Does anyone know why I'm getting this error when deploying to Vercel? I don't get it when deploying to Fly.io. It also works in development. Here's a sandbox. https://codesandbox.io/p/github/stevebarakat/tutorial-kit/main?import=true
Error: ENOENT: no such file or directory, open '/var/task/content/1-getting-started/1-intro-to-state/1-basic-state.mdx'
    at async open (node:internal/fs/promises:639:25)
    at async Object.readFile (node:internal/fs/promises:1249:14)
    at async /var/task/.next/server/app/[part]/[chapter]/[lesson]/page.js:107:29494
    at async c (/var/task/.next/server/app/[part]/[chapter]/[lesson]/page.js:95:9697) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/task/content/1-getting-started/1-intro-to-state/1-basic-state.mdx',
  digest: '416534407'
}

4 Replies

German PinscherOP
I also get the error for the public folder:
Error: ENOENT: no such file or directory, scandir '/var/task/public/content/1-getting-started/1-intro-to-state/1-basic-state/starter'
    at async Object.readdir (node:internal/fs/promises:948:18)
    at async I (/var/task/.next/server/app/[part]/[chapter]/[lesson]/page.js:107:29779)
    at async AD (/var/task/.next/server/app/[part]/[chapter]/[lesson]/page.js:95:8732) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/var/task/public/content/1-getting-started/1-intro-to-state/1-basic-state/starter',
  digest: '2831528635'
}
Giant panda
may be due to windows and linux os and git lower case/ upper case
Northeast Congo Lion
Are you trying to use an explict file open in your code? For Vercel, you don't have a copy of your full source tree in the deployed project, just what is in the .next build folder. Any files you need have to be referenced from there. If your content folder is not copied into your build folder, it will not be on Vercel's deployment.

You should reference file paths relative to process.cwd()

You can copy data files you need into the build directory using copy-webpack-plugin or some equivalent in your next config file.
German PinscherOP
Okay. I'll give that a shot. Thanks!