Next js component file as text
Unanswered
Alaska pollock posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
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
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](https://cdn.discordapp.com/embed/avatars/3.png)
Alaska pollockOP
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Alaska pollockOP
@Siberian Flycatcher
@Eric Burel
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Alaska pollockOP
@Transvaal lion can you help
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Manx
what the hell
![Avatar](https://cdn.discordapp.com/avatars/769111741098622976/a00ea6fb13337fd9ef76154f8e3cb990.webp?size=256)
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](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
btw its: right click -> reply with issue -> ping (i think is its name)
![Avatar](https://cdn.discordapp.com/avatars/769111741098622976/a00ea6fb13337fd9ef76154f8e3cb990.webp?size=256)
Eric Burel
Edit: nvm found the button thank you 🙂
![Image](https://cdn.discordapp.com/attachments/1172555283952828416/1173553207721603082/image.png?ex=65645f98&is=6551ea98&hm=a9bd0d67d53846fdadd7e9098b07aeb1c6b4e52bf4e41c33cc4c397d433ef6ec&)
it's in "Applications"
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
ahh your not in english
![Avatar](https://cdn.discordapp.com/avatars/769111741098622976/a00ea6fb13337fd9ef76154f8e3cb990.webp?size=256)
Eric Burel
Non ^^ and they made a weird translation