I am trying to read .env
in next.js inside the next.config.js
this is how it looks
require("dotenv").config({ path: require("find-config")(".env") })
console.log(process.env.API_URL)
module.exports = {
reactStrictMode: true,
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
},
baseURL: process.env.API_URL,
}
and this prints the value from .env
on the server console.
And now If i use this baseUrl
in the component like this
import config from "../../next.config";
const axiosInstance = axios.create({ baseURL: config.baseURL });
then even code does not compile
Module not found: Can't resolve 'fs'
Import trace for requested module:
./next.config.js
what can be the issue?