JustAsking
JustAsking

Reputation: 121

Having Trouble using env variables in Next.js

Converted my react application to next.js and trying to add my env.local files to my next.js application but it is not working.

I tried: adding env.local to the root of my folder and also looked at the documentation along with restarting my server

documentation

SERVICE_ID ="default_service"
USER_ID = "user_ra9adakLqa47SSFhb4QI3Swp"
TEMPLATE_ID ="template_xocwssd1upm"

console.warn(process.env.USER_ID)
await emailjs.send(
    process.env.SERVICE_ID,
    process.env.TEMPLATE_ID,
    templateParams,
    process.env.USER_ID
);

undefined

An user-id is required

Upvotes: 1

Views: 254

Answers (1)

Danila
Danila

Reputation: 18486

If you want to use env variables on the client (in your React components) then you need to prefix them with NEXT_PUBLIC_, or use older way of exposing them to the client inside next.config.js.

Upvotes: 1

Related Questions