Netlify dev environment variables not being injected

Today with netlify-cli environment variables are not being injected when I run netlify dev command. Yesterday I was not having any issues with this. I did update to the latest version of netlify-cli (12.5.0).

Logs from yesterday…

$ netlify dev
◈ Netlify Dev ◈
◈ Injected netlify.toml file env var: NPM_FLAGS
◈ Injected site settings env var: FBM_APP_PASSWORD
◈ Injected site settings env var: DEV_PS_API_SECRET
◈ Injected site settings env var: DEV_PS_API_KEY
◈ Injected site settings env var: DEV_ODM_API_KEY
◈ Injected site settings env var: DATABASE_URL
◈ Injected site settings env var: LOCAL_MONGODB_URI
◈ Injected site settings env var: PS_API_SECRET
◈ Injected site settings env var: LOCAL_PS_API_KEY
◈ Injected site settings env var: ODM_API_KEY
◈ Injected site settings env var: DEV_MONGODB_URI
◈ Injected site settings env var: FBM_APP_USER
◈ Injected site settings env var: LOCAL_PS_API_SECRET
◈ Injected site settings env var: PS_API_KEY
◈ Injected site settings env var: LOCAL_NEXTAUTH_URL
◈ Injected site settings env var: LOCAL_ODM_API_KEY
◈ Injected site settings env var: MONGODB_URI
◈ Ignored general context env var: LANG (defined in process)
◈ Functions server is listening on 57276
◈ Setting up local development server
​
────────────────────────────────────────────────────────────────
  Netlify Build                                                 
────────────────────────────────────────────────────────────────
​
❯ Version
  @netlify/build 27.20.6
​
❯ Flags
  {}
​
❯ Current directory
  /Users/bobhall/develop/ondeckmanager
​
❯ Config file
  /Users/bobhall/develop/ondeckmanager/netlify.toml
​
❯ Context
  dev
​
❯ Using Next.js Runtime - v4.29.4
​
────────────────────────────────────────────────────────────────
  1. @netlify/plugin-nextjs (onPreDev event)                    
────────────────────────────────────────────────────────────────
​
Patching /Users/bobhall/develop/ondeckmanager/node_modules/.pnpm/next@12.3.1_fg2utqowjbkxtwv6d354q3ipaa/node_modules/next/dist/server/base-server.js
Done
Patching /Users/bobhall/develop/ondeckmanager/node_modules/.pnpm/next@12.3.1_fg2utqowjbkxtwv6d354q3ipaa/node_modules/next/dist/server/next-server.js
Done
​
(@netlify/plugin-nextjs onPreDev completed in 63ms)
​
────────────────────────────────────────────────────────────────
  2. Run command for local development                          
────────────────────────────────────────────────────────────────
​
◈ Starting Netlify Dev with Next.js

> on-deck-manager@0.1.2 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
✔ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml
​
(dev.command completed in 1s)

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Loaded edge function next-dev
event - compiled client and server successfully in 2.4s (1145 modules)
wait  - compiling /_error (client and server)...
wait  - compiling /ping (client and server)...
wait  - compiling /api/v2/nafa/standings/[...slug] (client and server)...
wait  - compiling /nafa/results/standings/[id] (client and server)...
event - compiled client and server successfully in 1464 ms (2065 modules)
Using Local mongo db settings
Using Local mongo db settings
HANDLING DEV MODE

log from today…

$ netlify dev
◈ Netlify Dev ◈
◈ Injected netlify.toml file env var: NPM_FLAGS
◈ Ignored general context env var: LANG (defined in process)
◈ Setting up local development server
​
  Netlify Build                                                 
────────────────────────────────────────────────────────────────
​
❯ Version
  @netlify/build 29.3.0
​
❯ Flags
  {}
​
❯ Current directory
  /Users/bobhall/develop/ondeckmanager
​
❯ Config file
  /Users/bobhall/develop/ondeckmanager/netlify.toml
​
❯ Context
  dev
​
❯ Using Next.js Runtime - v4.29.4
​
  1. @netlify/plugin-nextjs (onPreDev event)                    
────────────────────────────────────────────────────────────────
​
Patching /Users/bobhall/develop/ondeckmanager/node_modules/.pnpm/next@12.3.1_fg2utqowjbkxtwv6d354q3ipaa/node_modules/next/dist/server/base-server.js
Done
Patching /Users/bobhall/develop/ondeckmanager/node_modules/.pnpm/next@12.3.1_fg2utqowjbkxtwv6d354q3ipaa/node_modules/next/dist/server/next-server.js
Done
​
(@netlify/plugin-nextjs onPreDev completed in 22ms)
​
  2. Run command for local development                          
────────────────────────────────────────────────────────────────
​
◈ Starting Netlify Dev with Next.js

> on-deck-manager@0.1.2 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using wasm build of next-swc
warn  - Attempted to load @next/swc-darwin-arm64, but it was not installed
✔ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml
​
(dev.command completed in 1s)

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Loaded edge function next-dev
event - compiled client and server successfully in 1873 ms (1161 modules)
wait  - compiling /nafa (client and server)...
wait  - compiling /_error (client and server)...
event - compiled client and server successfully in 1024 ms (1830 modules)
Using Local mongo db settings
error - helpers/api/mongodb.js (23:8) @ eval
error - Error: Define the MONGODB_URI environmental variable
    at eval (webpack-internal:///./helpers/api/mongodb.js:27:11)
    at Object../helpers/api/mongodb.js (/Users/bobhall/develop/ondeckmanager/.next/server/pages/nafa.js:88:1)
    at __webpack_require__ (/Users/bobhall/develop/ondeckmanager/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./pages/nafa.js:8:77)
    at Object../pages/nafa.js (/Users/bobhall/develop/ondeckmanager/.next/server/pages/nafa.js:517:1)
    at __webpack_require__ (/Users/bobhall/develop/ondeckmanager/.next/server/webpack-runtime.js:33:42)
    at __webpack_exec__ (/Users/bobhall/develop/ondeckmanager/.next/server/pages/nafa.js:1142:39)
    at /Users/bobhall/develop/ondeckmanager/.next/server/pages/nafa.js:1143:28
    at Object.<anonymous> (/Users/bobhall/develop/ondeckmanager/.next/server/pages/nafa.js:1146:3)
    at Module._compile (node:internal/modules/cjs/loader:1165:14) {
  page: '/nafa'
}
  21 | // check the MongoDB URI
  22 | if (!MONGODB_URI) {
> 23 |   throw new Error('Define the MONGODB_URI environmental variable');
     |        ^
  24 | }
  25 | 
  26 | // check the MongoDB DB
warn  - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works
TypeError: Failed to fetch
    at __webpack_require__.hmrM (http://localhost:8888/_next/static/chunks/webpack.js?ts=1672410647571:1174:20)

Is there a new way to handle environment variables with the newest version of netlify-cli?

  • we need to know your netlify site name: keen-ritchie-2146a3.netlify.app

Is CLI still connected to your site? Could you try netlify link to be sure?

Thanks @hrishikesh. That solved the issue.

Bob