Opengraph-image route on Node.js runtime is not finding a local asset

Hello,

I am using Next.js’s feature of generating opengraph-images with code, so all of my blog posts have OG image without effort.

Due to function size limitations, I am using Node.js runtime and not edge, which is fine.

I followed the documentation on using local assets with Node.js runtime, using path join and process.cwd() + path to image from project root.

Unfortunately, the locally stored image is not found (I can see it in logs, see bellow).

⨯ Error: ENOENT: no such file or directory, open '/var/task/images/avatars/vojtech-mares.png'
    at async open (node:internal/fs/promises:639:25)
    at async readFile (node:internal/fs/promises:1249:14)
    at async f (/var/task/.next/server/app/blog/[slug]/opengraph-image/route.js:1:1681)
    at async /var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:45153
    at async eG.execute (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:35441)
    at async eG.handle (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:46454)
    at async doRender (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/server/base-server.js:1440:42)
    at async responseGenerator (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/server/base-server.js:1719:28)
    at async NextNodeServer.renderToResponseWithComponentsImpl (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/server/base-server.js:1726:28)
    at async NextNodeServer.renderPageComponent (/var/task/node_modules/.pnpm/next@15.0.0-canary.115_@babel+core@7.25.2_babel-plugin-react-compiler@0.0.0-experimental-938c_uwi3ycwai7h4u3rcfo6camv74u/node_modules/next/dist/server/base-server.js:2065:24) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/task/images/avatars/vojtech-mares.png'
}

When I tested this locally with pnpm run dev, everything is working fine.

What am I missing?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.