Skip to content

NextJS: How to access files in production deployment #6

@timtnleeProject

Description

@timtnleeProject

Problem

My nextJS Apis have accessed some config files through the file system,
for example, the /posts folder under the project root.

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

const postsDirectory = path.join(process.cwd(), "posts");

const filenames = fs.readdirSync(postsDirectory); // failed in deployment

However, the folder structure has been optimized(? and is not as same as local development and local build.

So basically the /posts folder isn't there in the deployed environment.

Solution

vercel/next.js#8251 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions