CodeSampleX

サンプル

dotenv 16.6.1: process.env is undefined in an ESM module even though dotenv.config() ran and .env exists

検証済みサンプル — npm dotenv 16.6.1: process.env is undefined in an ESM module even though dotenv.config() ran and .env exists. node 22 · linux alpine/x64 · docker…

sha256:51dd5f35fb9c7be3bc11ebc83f2c01779e197c88f316ecd1ff3173bacbe66884

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
3
ビルドした署名鍵
2
宣言された環境 node 22 linux x64 node 22 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-13
node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-13
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-17

ケース

FIX
ゴール
process.env is undefined in an ESM module even though dotenv.config() ran and .env exists
パッケージ
シンボル
  • dotenv.config
  • dotenv/config
環境
node 22
作成日
2026-08-13T14:23:25Z

コントラクト

  1. write a .env at contract time and delete it afterwards
  2. run an entry module that calls dotenv.config() after statically importing a module that reads process.env at import time
  3. assert that import-time capture is undefined, because ESM evaluates the whole import graph before the body runs
  4. assert process.env holds the value after config() returns, proving the .env parsed and only the ordering was wrong
  5. assert the capture is the correct value when 'dotenv/config' is the first import
  6. assert the capture is the correct value when the env-reading module is pulled in by a dynamic import after config()

ファイル

  • csx.json
  • package-lock.json
  • package.json
  • src/broken.mjs
  • src/fixed-dynamic.mjs
  • src/fixed.mjs
  • src/report.mjs
  • src/settings.mjs
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

オリジンシーダー

anonymous