diff --git a/.changeset/four-zebras-deliver.md b/.changeset/four-zebras-deliver.md new file mode 100644 index 000000000000..bd77438fa373 --- /dev/null +++ b/.changeset/four-zebras-deliver.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Make debug log for `.env` not found less scary diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index 561cbecd4034..7f90d8824e7a 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -954,6 +954,14 @@ describe.sequential("wrangler dev", () => { const output = fs.readFileSync("var.txt", "utf8"); expect(output).toMatch("custom"); }); + it("should show reasonable debug output if `.env` does not exist", async () => { + fs.rmSync(".env"); + writeWranglerConfig({ + main: "index.js", + }); + await runWranglerUntilConfig("dev --log-level debug"); + expect(std.debug).toContain(".env file not found at"); + }); }); }); diff --git a/packages/wrangler/src/config/index.ts b/packages/wrangler/src/config/index.ts index 8bea2aa5a00b..b6f30958c374 100644 --- a/packages/wrangler/src/config/index.ts +++ b/packages/wrangler/src/config/index.ts @@ -686,7 +686,13 @@ function tryLoadDotEnv(path: string): DotEnv | undefined { const parsed = dotenv.parse(fs.readFileSync(path)); return { path, parsed }; } catch (e) { - logger.debug(`Failed to load .env file "${path}":`, e); + if ((e as { code: string }).code === "ENOENT") { + logger.debug( + `.env file not found at "${path}". Continuing... For more details, refer to https://developers.cloudflare.com/workers/wrangler/system-environment-variables/` + ); + } else { + logger.debug(`Failed to load .env file "${path}":`, e); + } } }