Skip to content

feat: replace dotenv with native node:util parseEnv - #2181

Merged
aklinker1 merged 6 commits into
wxt-dev:mainfrom
HarrysonLadines:main
Mar 18, 2026
Merged

aklinker1 merged 6 commits into
wxt-dev:mainfrom
HarrysonLadines:main

Conversation

@HarrysonLadines

@HarrysonLadines HarrysonLadines commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This PR replaces the dotenv dependency with Node.js native node:util#parseEnv implementation.

  • Dependency reduction: Removed dotenv from package.json, reducing the project's dependency footprint.
  • Modern API integration: Refactored loadEnv to use node:fs and node:util, aligning WXT with the environment loading strategy used by Vite.
  • Priority Handling: Maintained the existing priority logic where specific files (like .local) override general ones using a robust .reverse() and Object.fromEntries approach.
  • Compatibility: Kept dotenv-expand to ensure support for variable expansion (e.g., VAR=$OTHER_VAR) remains functional for users.

Manual Testing

I verified the implementation using a standalone TypeScript script within the repository to confirm the native parseEnv behavior:

  1. Environmental Parsing: Verified that node:util#parseEnv correctly maps key-value pairs from .env files into a JavaScript object.
  2. Priority Logic: Confirmed that reversing the envFiles array before calling Object.fromEntries ensures that specific files (like .env.local) correctly override base configurations.
  3. Execution Environment: Successfully validated the logic using bun to ensure compatibility with the project's current development workflow.
  4. Expansion Support: Confirmed that dotenv-expand remains functional for nested variables after the native parsing stage.

Related Issue

This PR closes #2176

@netlify

netlify Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 90cb1d2
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/69babe6714e0be000836e360
😎 Deploy Preview https://deploy-preview-2181--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the pkg/wxt Includes changes to the `packages/wxt` directory label Mar 6, 2026
@HarrysonLadines

Copy link
Copy Markdown
Contributor Author

I've updated the pnpm-lock.yaml and amended the commit to sync dependencies. The previous deploy failure should be resolved now.

@aklinker1 aklinker1 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good. Checks might fail due to formatting, run pnpm prettier --write if it does.

Edit: I had some issues with checks on main, they have been fixed. Looks like PR checks are failing, fix them and we can merge this PR.

@aklinker1 aklinker1 changed the title feat: replace dotenv with native node:util parseEnv feat: replace dotenv with native node:util parseEnv Mar 6, 2026
@codecov

codecov Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.22%. Comparing base (e3a80b8) to head (90cb1d2).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
packages/wxt/src/core/utils/env.ts 58.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2181      +/-   ##
==========================================
- Coverage   76.32%   76.22%   -0.10%     
==========================================
  Files         115      115              
  Lines        3067     3092      +25     
  Branches      681      684       +3     
==========================================
+ Hits         2341     2357      +16     
- Misses        644      652       +8     
- Partials       82       83       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@2181

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@2181

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@2181

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@2181

@wxt-dev/is-background

npm i https://pkg.pr.new/@wxt-dev/is-background@2181

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@2181

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@2181

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@2181

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@2181

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@2181

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@2181

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@2181

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@2181

wxt

npm i https://pkg.pr.new/wxt@2181

commit: 90cb1d2

@aklinker1

aklinker1 commented Mar 17, 2026 •

Copy link
Copy Markdown
Member

Hey, as mentioned in #2185, this is only available in Node 22. Can you change this PR to be based off major instead so it is included as a breaking change?

Actually, double checked, this was added in 20.12, so it's fine:

image

https://nodejs.org/api/util.html#utilparseenvcontent

@aklinker1
aklinker1 enabled auto-merge (squash) March 18, 2026 15:02
@aklinker1
aklinker1 merged commit ace6c20 into wxt-dev:main Mar 18, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for helping make WXT better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/wxt Includes changes to the `packages/wxt` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace dotenv with builtins

2 participants