{"id":406,"hash":"c603997e0acd08e179fb7f980a4a69508b302934054ffb399ecba6d19b16b5cf","pattern":"next.js environment variables are undefined (Next.js 10.0.5)","full_message":"I am coding a website with Next.js and I tried to add google Tag Manager.\n\nI followed the tutorial on the Next.js Github example but for some reasons I can't access to my environment variables. \n\nIt says my variable is undefined. \n\nI created a file .env.local on my project folder (at the same level as components, node_modules, pages, etc)\n\nIn this file I created a variable like this (test purpose) : \n\nNEXT_PUBLIC_DB_HOST=localhost\n\nAnd on my index page I tried this code : \n\nconsole.log(\"test \", process.env.NEXT_PUBLIC_DB_HOST);\n\nBut in my console I get a \"test  undefined\". \n\nI tried to put my variable into an .env file instead, without success.\n\nWhat I am doing wrong ?","ecosystem":"npm","package_name":"environment-variables","package_version":null,"solution":"This envs just works in Server Side. To access this envs in Client Side, you need declare in the next.config.js\n\nThis way:\n\nmodule.exports = {\n  reactStrictMode: true,\n  env: {\n    BASE_URL: process.env.BASE_URL,\n  }\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/66137368/next-js-environment-variables-are-undefined-next-js-10-0-5","votes":110,"created_at":"2026-04-19T04:51:06.838895+00:00","updated_at":"2026-04-19T04:51:06.838895+00:00"}