首页 > 解决方案 > Nextjs 如何在 Vercel 上将自定义文件夹移动到生产环境

问题描述

我最近开始在 NextJS 环境上进行开发。在我的项目中,我的根目录的文件夹中有一些 JSON 文件,我在代码中读取了这些文件的内容。它在我的本地机器上运行良好,但是当它在 vercel 服务器上投入生产时,它无法读取该文件,因为该文件在服务器上不存在。

这是我在本地机器中的项目文件结构:

|--.next
|--components
|--jsonfiles
|--node_modules
|--pages
|--public
|--package.json

(and more)...

但是部署后,当我使用它读取根目录的内容时fs.readdirSync("./"),它只包含以下文件和目录:

|--.next
|--___next_launcher.js
|--___vc_bridge.js
|--node_modules
|--package.json

这是我读取文件的代码:

   const fs = require('fs');
   const rawcontent = fs.readSync('./jsonfiles/list.json');
   const list:array[] = JSON.parse(rawcontent);
   ...

这个问题有什么解决办法吗?

标签: typescriptnext.jsvercel

解决方案


推荐阅读