Skip to content

.env file is no longer auto-imported #2266

Closed

Description

@hyunbinseo

Describe the bug

After updating wxt from 0.20.20 to 0.20.21, this error is caused:

Error: Missing required config: CHROME_EXTENSION_ID, FIREFOX_EXTENSION_ID

I have these environment variables defined in the .env file.

This is probably caused by #2181

- import { config } from 'dotenv';

Simply importing dotenv/config auto-imports the .env file. From the README:

// index.js
require('dotenv').config()
// or import 'dotenv/config' // for esm

console.log(`Hello ${process.env.HELLO}`)

That's it. process.env now has the keys and values you defined in your .env file.

Reproduction

Steps to reproduce

No response

System Info

System:
  OS: Windows 11 10.0.26200
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 6.69 GB / 31.48 GB
Binaries:
  Node: 24.14.1 - C:\Users\hyunb\AppData\Local\fnm_multishells\6356_1776160262050\node.EXE
  npm: 11.11.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\6356_1776160262050\npm.CMD
  pnpm: 10.33.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\6356_1776160262050\pnpm.CMD
  Deno: 2.4.0 - C:\Users\hyunb\.deno\bin\deno.EXE
Browsers:
  Chrome: 147.0.7727.56
  Edge: Chromium (140.0.3485.54)
  Firefox: 149.0.2 - C:\Program Files\Mozilla Firefox\firefox.exe

Used Package Manager

npm

Validations

Activity

  1. added
    pending-triage
    on Apr 14, 2026
  2. added theissue type on Apr 14, 2026
  3. aklinker1 commented on Apr 14, 2026

    @aklinker1
    Member

    Very weird. Not sure why this change would have effected wxt submit, that's an alias for publish-browser-extension, so it's more likely a change there that broke it.

    WXT was never importing from dotenv/config, it manually called config(), so that's not the problem.

    Couple of things I noticed:

    1. Your env is defined in .env, but publish-browser-extension has always loaded .env.submit, it's never loaded .env
    2. You're also trying to load IDs from github action secrets: https://github.com/hyunbinseo/better-surf/blob/23d3e799c328b7e982799b13caf7807a78bb1d90/.github/workflows/submit.yml#L34-L40, which could be conflicting... but it worked for your 27 release.

    Looking at your lockfile, it looks like the last success was with [email protected], and it failed after upgrading to 4.0.5... Odd, that was a very small release that didn't touch env at all... Hmm, that does make me think WXT might be the cause...

    Regardless, you should be putting this files in .env.submit, not .env. I'm not sure why your CI worked at all. Alternatively, you could add NODE_OPTIONS: ---env-file=.env on your submit step's environment, to have node load that file in addition to .env.submit.

          - name: Submit to stores
            run: |
              pnpm wxt submit \
                --chrome-zip .output/*-chrome.zip \
                --firefox-zip .output/*-firefox.zip --firefox-sources-zip .output/*-sources.zip
            env:
    +         NODE_OPTIONS: --env-file=.env
              CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
              CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
              CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }}
              CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }}
              FIREFOX_EXTENSION_ID: ${{ secrets.FIREFOX_EXTENSION_ID }}
              FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }}
              FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }}
  4. hyunbinseo commented on Apr 14, 2026

    @hyunbinseo
    ContributorAuthor

    @aklinker1 thanks for the quick review.

    I was using .env.submit briefly when I was directly using publish-browser-extension directly:

    because it wasn't autoloading the .env file. This is why I believe wxt was importing .env in the previous version.

  5. hyunbinseo commented on Apr 14, 2026

    @hyunbinseo
    ContributorAuthor

    Isn't .env supposed be loaded in all cases though?

    WXT supports dotenv files the same way as Vite. Create any of the following files:

    plaintext

    .env
    .env.local
    .env.[mode]
    .env.[mode].local
    .env.[browser]
    .env.[browser].local
    .env.[mode].[browser]
    .env.[mode].[browser].local
    

    And any environment variables listed inside them will be available at runtime:

    https://wxt.dev/guide/essentials/config/environment-variables.html#dotenv-files

  6. aklinker1 commented on Apr 14, 2026

    @aklinker1
    Member

    The submit commands are special, they are just aliases to publish-browser-extension. env files are loaded when we resolve WXT's config internally, but that's not necessary to forward the CLI command to another CLI.

    Also note "runtime" in "And any environment variables listed inside them will be available at runtime" - the CLI is build-time, not runtime. Runtime is when the extension is running in the browser.

  7. hyunbinseo commented on Apr 14, 2026

    @hyunbinseo
    ContributorAuthor

    Fixed in hyunbinseo/better-surf@14375f7

    Maybe the behavior of loadEnvFile in wxt.config.ts changed?

    The NODE_OPTIONS suggestion did not work: https://github.com/nodejs/node/issues/511474

    node: --env-file= is not allowed in NODE_OPTIONS

  8. aklinker1 commented on Apr 14, 2026

    @aklinker1
    Member

    OK, found the problem

    I modified publish-browser-extension to print the resolved chrome config to see what extensionId it resolved internally.

    git checkout v0.0.28
    $ CHROME_EXTENSION_ID="" pnpm wxt submit --chrome-zip chrome.zip
    {
      zip: 'chrome.zip',
      extensionId: undefined,
      ...
    }
    $ pnpm wxt submit --chrome-zip chrome.zip
    {
      zip: 'chrome.zip',
      extensionId:'jhpnholkflkpnadabmadfcfgnbekijjf',
      ...
    }
    
    git checkout v0.0.27
    $ CHROME_EXTENSION_ID="" pnpm wxt submit --chrome-zip chrome.zip
    {
      zip: 'chrome.zip',
      extensionId:'jhpnholkflkpnadabmadfcfgnbekijjf',
      ...
    }
    $ pnpm wxt submit --chrome-zip chrome.zip
    {
      zip: 'chrome.zip',
      extensionId:'jhpnholkflkpnadabmadfcfgnbekijjf',
      ...
    }
    

    In v0.0.27, even if the env var was set to an empty string, it worked. But in v0.0.28, if you set the env var to an empty string, it would not be overriden.


    I was confused at first because my local testing couldn't reproduce the problem. But then I remembered your action is passing a blank string for the CHROME_EXTENSION_ID env var. You secret is empty, and it's listed here, thus a blank string. You can see this by looking at the workflow logs as well:

    Image

    So the PR you originally mentioned was the cause - after that PR, env vars that are blank strings are not overridden.

    Specifically, if you modify WXT's loadEnv as follows:

      console.log({ parsed })
      const res = expand({
        parsed,
        processEnv: { ...process.env }
      });
      console.log({ parsed, res })
      console.log("REAL", process.env)

    We get the following logs:

    {
      parsed: {
        CHROME_EXTENSION_ID: 'jhpnholkflkpnadabmadfcfgnbekijjf',
        FIREFOX_EXTENSION_ID: 'better-surf',
        FIREFOX_EXTENSION_UUID: 'f7ca4a3a-350a-45d5-a0fa-bf27cd37aa47'
      }
    }
    {
      parsed: {
        CHROME_EXTENSION_ID: 'jhpnholkflkpnadabmadfcfgnbekijjf',
        FIREFOX_EXTENSION_ID: 'better-surf',
        FIREFOX_EXTENSION_UUID: 'f7ca4a3a-350a-45d5-a0fa-bf27cd37aa47'
      },
      res: {
        parsed: {
          CHROME_EXTENSION_ID: 'jhpnholkflkpnadabmadfcfgnbekijjf',
          FIREFOX_EXTENSION_ID: 'better-surf',
          FIREFOX_EXTENSION_UUID: 'f7ca4a3a-350a-45d5-a0fa-bf27cd37aa47'
        },
        processEnv: {
          CHROME_EXTENSION_ID: 'jhpnholkflkpnadabmadfcfgnbekijjf',
          ...
        }
      }
    }
    REAL {
      ...
      CHROME_EXTENSION_ID: '',
      ...
    }
    

    So you can see WXT no longer applies the result of dotenv-expand to the real process.env, as dotenv was doing before.

    This only seems to cause issues if you have the same env var set multiple ways, once outside a .env and once inside a .env. I think the current behavior is more correct - you clearly set the env var to a blank string when running the command, which should take priority.

    If we wanted to fix this, the solution would be to let dotenv-expand modify the real process.env like so:

      const res = expand({
        parsed,
    -   processEnv: { ...process.env }
    +   processEnv: process.env
      });

    Vite doesn't do this, but the package's docs imply we should 🤔

  9. aklinker1 commented on Apr 14, 2026

    @aklinker1
    Member

    BUT vite doesn't use this to make variables available via process.env - it uses the result to replace import.meta.env.* in your bundle.

    So I think I'll make this change.

  10. removed
    pending-triage
    on Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions