How to load assetPrefix from env in next.config.js?
Unanswered
Najmus Sakib posted this in #help-forum
I want to use next env in next.config.js
I am loading this code to load env in next.config.js
I got output in my terminal
But it fails to load with cdn. If I give value in direct string like this
assetPrefix: ASSETS_CDN_URLI am loading this code to load env in next.config.js
const {loadEnvConfig} = require('@next/env');
loadEnvConfig(process.cwd());
const isProd = process.env.NODE_ENV === 'production';
const ASSETS_CDN_URL = process.env.NEXT_PUBLIC_ASSETS_CDN_URL;
console.log('from next.config.js', ASSETS_CDN_URL);I got output in my terminal
info - Loaded env from /home/ubuntu/frontend/.env
from next.config.js https://cdn-server2.cdn.comBut it fails to load with cdn. If I give value in direct string like this
assetPrefix: 'https://cdn-server2.cdn.com' It works perfectly, I have two servers I have two cdn server for this, How can I resolve this issue? Now I have to manually set the server in static , that is full manual. How can i load assetPrefix from my env?2 Replies
Birman
@Najmus Sakib - were you able to solve this?