typescript - 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);
...
这个问题有什么解决办法吗?
解决方案
推荐阅读
- css - 无法在 iPad 上的 Bootstrap 3 网站中折叠导航
- python - 得到一个奇怪的 _tkinter.TclError: unknown option
- python - 在 PyQt5 中打开多个窗口时遇到问题
- ios12 - 子类 INObject?
- mysql - 在 MySQL 中使用 CASE 将值设置为 NULL 或空白
- c - 融合两个排序的数组
- php - 隐藏的mod仅针对某些路径重写到子文件夹
- php - PHP 不显示 HTML 输入
- android - 如果 gradle 中包含生命周期扩展,kotlin-android-extensions 将停止工作
- php - 使用 Digital Ocean 通过 IP 在 nginx 服务器上配置多站点