From afbe884dadaedf4aa05724dc4680c71acee9eb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 25 Sep 2024 12:37:51 +0200 Subject: [PATCH] refactor(core): Load dotenv as early as possible (no-changelog) (#10948) --- packages/cli/bin/n8n | 7 +++++++ packages/cli/src/config/index.ts | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/cli/bin/n8n b/packages/cli/bin/n8n index 6eca06085..c4b593ccc 100755 --- a/packages/cli/bin/n8n +++ b/packages/cli/bin/n8n @@ -43,6 +43,13 @@ require('express-async-errors'); require('source-map-support').install(); require('reflect-metadata'); +// Skip loading dotenv in e2e tests. +// Also, do not use `inE2ETests` from constants here, because that'd end up code that might read from `process.env` before the values are loaded from an `.env` file. +if (process.env.E2E_TESTS !== 'true') { + // Loading dotenv early ensures that `process.env` is up-to-date everywhere in code + require('dotenv').config(); +} + if (process.env.NODEJS_PREFER_IPV4 === 'true') { require('dns').setDefaultResultOrder('ipv4first'); } diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts index 6661057b9..0c799aa8a 100644 --- a/packages/cli/src/config/index.ts +++ b/packages/cli/src/config/index.ts @@ -1,6 +1,5 @@ import { GlobalConfig } from '@n8n/config'; import convict from 'convict'; -import dotenv from 'dotenv'; import { flatten } from 'flat'; import { readFileSync } from 'fs'; import merge from 'lodash/merge'; @@ -22,8 +21,6 @@ if (inE2ETests) { process.env.N8N_PUBLIC_API_DISABLED = 'true'; process.env.SKIP_STATISTICS_EVENTS = 'true'; process.env.N8N_SECURE_COOKIE = 'false'; -} else { - dotenv.config(); } // Load schema after process.env has been overwritten