Next.js Discord

Discord Forum

Next js component file as text

Unanswered
Alaska pollock posted this in #help-forum
Open in Discord
Avatar
Alaska pollockOP
Question
I am accessing a file from the server page in app directory

file path
components/navbar/navbar_01/index.tsx

from some page in app dir I am using my server function
path app/component/abc/index.tsx

my server function

import fs from "fs"
import path from "path"

export async function getComponentFileText(componentFilePath: string) {
const codeFile = await fs.readFileSync(
path.resolve(process.cwd(), "components", componentFilePath),
"utf-8"
)
return codeFile
}
on local it is a working file but on vecel it gives an error

Error: ENOENT: no such file or directory, open '/var/task/components/showcase/navbars/nav_02/index.tsx'
at Object.openSync (node:fs:603:3)
at Object.readFileSync (node:fs:471:35)
at getComponentFileText (/var/task/.next/server/app/(MainLayout)/components/[componentName]/page.js:1:5382)
at Iframe (/var/task/.next/server/app/(MainLayout)/components/[componentName]/page.js:1:5664)
at ev (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:75:11059)
at /var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:75:21868
at Array.toJSON (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:75:25185)
at stringify (<anonymous>)
at eT (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:75:13688)
at eP (/var/task/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:75:14214) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/var/task/components/showcase/navbars/nav_02/index.tsx'
}
also don't why vercel appending "/var/task/" in file ulr
on my local its workig fine

13 Replies

Avatar
Alaska pollockOP
Avatar
Alaska pollockOP
@Siberian Flycatcher
@Eric Burel
Avatar
Alaska pollockOP
@Transvaal lion can you help
Avatar
Manx
what the hell
Avatar
Eric Burel
@Alaska pollock ok I can't find the comamnd but basically don't notify people not in the discussion
then, please start by the basic tutorials
we can only help if you help yourself first
Avatar
risky
btw its: right click -> reply with issue -> ping (i think is its name)
Avatar
Eric Burel
Edit: nvm found the button thank you 🙂
Image
it's in "Applications"
Avatar
risky
ahh your not in english
Avatar
Eric Burel
Non ^^ and they made a weird translation