I am using monorepo structure using yarn berry(3.6) workspace.
Since our API URLs are almost identical, we plan to create and use API EndPoints inside the packages.
However, in the process of using the API instance, I confirmed that the .env file did not work normally.
I would be grateful if you could tell me how to solve it.
The project that uses that axios instance module is the next.js project.
/packages/common-utils/http/core.ts
import axios, { AxiosInstance } from "axios";
import {config} from dotenv ;
config()
console.log(process.env.BASE_URL);//undefined
const request: AxiosInstance = axios.create({
baseURL: process.env.BASE_URL, //it is not working, undefined
timeout: 2500,
withCredentials: true,
headers: {
accept: "application/json"
}
});
export default request;
services/next-app/src/pages/index.jsx
import { core } from "@common/common-utils";
...
Below is my project structure.
my-workspace/
├── packages/
│ ├── common-utils/
│ │ ├── http/
│ │ │ └── core.ts
│ │ ├── index.js
│ │ ├── package.json
│ │ └── .env
├── services/
│ ├── next-app/
├── package.json
└── yarn.lock
The part I doubt is that when I import it from next.js, I feel like I can t find it when it s built in the process.
I m wondering is there any other way to use .env??
Or do I have to go through a separate build process?