diff --git a/src/node.cc b/src/node.cc index deaed9ec3d74a9c..c2ae191bdc18a06 100644 --- a/src/node.cc +++ b/src/node.cc @@ -865,11 +865,9 @@ static ExitCode InitializeNodeWithArgsInternal( if (!file_paths.empty()) { CHECK(!per_process::v8_initialized); - auto cwd = Environment::GetCwd(Environment::GetExecPath(*argv)); for (const auto& file_path : file_paths) { - std::string path = cwd + kPathSeparator + file_path; - auto path_exists = per_process::dotenv_file.ParsePath(path); + bool path_exists = per_process::dotenv_file.ParsePath(file_path); if (!path_exists) errors->push_back(file_path + ": not found"); } diff --git a/test/parallel/test-dotenv-edge-cases.js b/test/parallel/test-dotenv-edge-cases.js index 9735a89618172c9..23e3e037418351f 100644 --- a/test/parallel/test-dotenv-edge-cases.js +++ b/test/parallel/test-dotenv-edge-cases.js @@ -2,6 +2,7 @@ const common = require('../common'); const assert = require('node:assert'); +const path = require('node:path'); const { describe, it } = require('node:test'); const validEnvFilePath = '../fixtures/dotenv/valid.env'; @@ -25,6 +26,18 @@ describe('.env supports edge cases', () => { assert.strictEqual(child.code, 0); }); + it('supports absolute paths', async () => { + const code = ` + require('assert').strictEqual(process.env.BASIC, 'basic'); + `.trim(); + const child = await common.spawnPromisified( + process.execPath, + [ `--env-file=${path.resolve(__dirname, validEnvFilePath)}`, '--eval', code ], + ); + assert.strictEqual(child.stderr, ''); + assert.strictEqual(child.code, 0); + }); + it('should handle non-existent .env file', async () => { const code = ` require('assert').strictEqual(1, 1)