Reading file content with `fs` but it always returns the same content as at build time
Answered
Chien Français Blanc et Noir posted this in #help-forum
Chien Français Blanc et NoirOP
Im doing following:
and it works completely fine in dev. But then when i build it, it always shows the version number of the version file at the time the project was built. How can i avoid this?
Im using NextJS 13 with the new app directory
const version = await fs.promises
.readFile(path.join(process.cwd(), 'bin', 'version'), 'utf-8')
.catch((error) => {
console.error('Failed to read version file', error)
return 'vUnknown'
})and it works completely fine in dev. But then when i build it, it always shows the version number of the version file at the time the project was built. How can i avoid this?
Im using NextJS 13 with the new app directory
Answered by Chien Français Blanc et Noir
i added
to my api route since it was considered static by next, this fixed it
export const dynamic = 'force-dynamic'to my api route since it was considered static by next, this fixed it
3 Replies
Chien Français Blanc et NoirOP
also, doing the same with files in the temp directory works just fine
Chien Français Blanc et NoirOP
i know the problem now, the api route is statically generated
Chien Français Blanc et NoirOP
i added
to my api route since it was considered static by next, this fixed it
export const dynamic = 'force-dynamic'to my api route since it was considered static by next, this fixed it
Answer