fix: stop dotenv from breaking island hydration
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
// This config runs in Node, outside Astro, so nothing has loaded `.env` yet. It must come
|
||||
// before the import below: `consts.ts` reads the environment as it is evaluated.
|
||||
import "dotenv/config";
|
||||
|
||||
import { defineConfig } from "@hey-api/openapi-ts";
|
||||
import { defaultPlugins } from "@hey-api/openapi-ts";
|
||||
|
||||
|
||||
+12
-6
@@ -1,9 +1,15 @@
|
||||
import dotenv from "dotenv";
|
||||
|
||||
if (typeof process !== "undefined") {
|
||||
dotenv.config();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads configuration from whichever environment this module ends up in.
|
||||
*
|
||||
* Nothing is loaded from disk here. This file travels into the browser bundle — components
|
||||
* call `getDefaultCurrency()` and friends — and it also runs on Cloudflare Workers, where
|
||||
* there is no filesystem to read a `.env` from. Calling `dotenv.config()` from here used to
|
||||
* throw `process.cwd is not a function` in the browser, which killed hydration for every
|
||||
* island that reached this module.
|
||||
*
|
||||
* Astro loads `.env` into `import.meta.env` on its own. The one caller that runs outside
|
||||
* Astro is `openapi-ts.config.ts`, and it loads `.env` itself.
|
||||
*/
|
||||
let runtimeEnv: Record<string, string>;
|
||||
|
||||
if (typeof import.meta !== "undefined" && import.meta.env) {
|
||||
|
||||
Reference in New Issue
Block a user