NETLIFY environment variable not set

I have been developing a vue.js site with nuxt.js on netlify.

About a month ago I was successfully referring to process.env.NETLIFY and checking it was "true".

The same code now no longer works. I have been able to dump the environment variables Netlify seems to be exposing and NETLIFY definitely not there.

The docs indicate that the env var should always be set:

Has there been a recent change to this functionality? why would a env var this critical to the platform be missing?

Following exported by returning process.env as the response to a request. I have also tried referring specifically to process.env.NETLIFY in case it is substituted by Netlify instead.

{
    "CMS_URL": "<...>",
    "CMS_KEY": "<...>",
    "EVENT_NAME": "<...>",
   
    "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST",
    "AWS_SESSION_TOKEN": "<...>",
    "NETLIFY_IMAGES_CDN_DOMAIN": "d33wubrfki0l68.cloudfront.net",
    "LAMBDA_TASK_ROOT": "/var/task",
    "AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/<...>",
    "LD_LIBRARY_PATH": "/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib",
    "AWS_LAMBDA_RUNTIME_API": "127.0.0.1:9001",
    "AWS_LAMBDA_LOG_STREAM_NAME": "2022/03/23/[$LATEST]d0b8fd15d85a4d3f877597e4e23817b3",
    "AWS_EXECUTION_ENV": "AWS_Lambda_nodejs14.x",
    "SITE_ID": "df86e60a-07a0-4dd8-9581-f9aff0dc3f6b",
    "AWS_XRAY_DAEMON_ADDRESS": "169.254.79.129:2000",
    "AWS_LAMBDA_FUNCTION_NAME": "<...>",
    "PATH": "/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin",
    "AWS_DEFAULT_REGION": "us-east-1",
    "PWD": "/var/task",
    "AWS_SECRET_ACCESS_KEY": "<...>",
    "LANG": "en_US.UTF-8",
    "LAMBDA_RUNTIME_DIR": "/var/runtime",
    "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand",
    "NODE_PATH": "/opt/nodejs/node14/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task",
    "TZ": ":UTC",
    "AWS_REGION": "us-east-1",
    "URL": "<...>",
    "AWS_ACCESS_KEY_ID": "<...>",
    "SHLVL": "0",
    "_AWS_XRAY_DAEMON_ADDRESS": "169.254.79.129",
    "_AWS_XRAY_DAEMON_PORT": "2000",
    "AWS_XRAY_CONTEXT_MISSING": "LOG_ERROR",
    "_HANDLER": "server.handler",
    "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1024",
    "SITE_NAME": "hoadley-hide",
    "NODE_EXTRA_CA_CERTS": "/etc/pki/tls/certs/ca-bundle.crt",
    "_X_AMZN_TRACE_ID": "Root=1-623b0f09-3a4744407318f7be5815c79a;Parent=2d9a76ed2151de12;Sampled=0",
    "VUE_ENV": "server"
  }

sitename: hoadley-hide

Hi, @krid-sdnera. The environment variable NETLIFY=true is defined in the build environment. This is the runtime environment variable that exists only during the site’s build and deploy process at Netlify.

The list of environment variables in your post comes from the deployed Function environment. The deployed function environment is not the same as the build environment. I would not expect NETLIFY=true to be defined in the Function environment.

The documentation you linked to tries to be clear about this:

Build metadata

  • NETLIFY : always true . Can be used to check if the build is running on Netlify.

This environment exists only in the “build environment” and not in the “function environment”. If there are other questions about this, please let us know.

2 Likes