【发布时间】:2022-02-14 17:11:43
【问题描述】:
我正在尝试在 React 中为 API_URL 使用 dotenv。当我在 Next.js 的 index.js 页面中使用它时。我收到此错误
Module not found: Can't resolve 'fs' in 'node_modules\dotenv\lib'
Import trace for requested module:
./pages/index.js
我正在通过这些方法使用 dotenv:
1.
import { config } from 'dotenv';
config();
import dotenv from 'dotenv';
dotenv.config();
const dotenv = require('dotenv');
dotenv.config();
我的 package.json 文件是:
"dependencies": {
"dayjs": "^1.10.7",
"dotenv": "^16.0.0",
"mongoose": "^6.2.1",
"next": "12.0.10",
"react": "17.0.2",
"react-dom": "17.0.2"
}
【问题讨论】:
标签: reactjs typescript next.js