The Silent Bug: Why Nuxt Couldn’t Read My .env File

I recently ran into a strange issue while migrating to Nuxt 4. It turns out my .env files weren't being detected at all. I’ve been dealing with some family matters lately (my mother was hospitalized), so I only just managed to sit down and debug this.

The Issue

For some reason, my .env file encoding had switched from UTF-8 to UTF-16 LE / UTF-16. (I think i can be from AI Agent that call powershell command to complete some task. Since I keep my .env in .gitignore, it wasn't immediately obvious what had changed in the file properties.

How to Fixed

If you're facing this, here’s how to fix it in VS Code:

  1. Open your .env file.
  2. Look at the Status Bar (bottom right). If it says UTF-16, click on it.
  3. Select "Save with Encoding".
  4. Choose UTF-8.

After saving, I re-ran the app and Gotcha!  the variables were correctly injected into runtimeConfig. Back to coding!

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.