fix: set env vars in both Deno.env and process.env for Node.js compat
The Node.js compatibility layer (npm: specifier) broke environment
variable passing because tools imported via npm: expect process.env,
not Deno.env.
Root cause: Recent commit added npm: specifier for Node compatibility,
but env injection code only set Deno.env.set(), not process.env.
Fix: Set environment variables in BOTH locations:
- Deno.env.set() for esm.sh imports
- globalThis.process.env for npm: imports
This restores functionality for tools like Firecrawl that require
API keys via environment variables.
Fixes regression from commit 8562eb5.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a39f28546a
commit
dc4846c7b1
1 changed files with 22 additions and 3 deletions
|
|
@ -491,14 +491,33 @@ async function executeTool(req: Request): Promise<Response> {
|
|||
if (envKeys.length > 0) {
|
||||
console.log(`🔐 Injecting ${envKeys.length} environment variables:`, envKeys);
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
Deno.env.set(key, String(value));
|
||||
console.log(` ✅ Set ${key} = ${String(value).substring(0, 10)}...`);
|
||||
const stringValue = String(value);
|
||||
|
||||
// Set in Deno environment (for esm.sh imports)
|
||||
Deno.env.set(key, stringValue);
|
||||
|
||||
// ALSO set in Node.js process.env (for npm: imports)
|
||||
// @ts-ignore - process is available in Node.js compatibility mode
|
||||
if (typeof globalThis.process !== 'undefined' && globalThis.process.env) {
|
||||
// @ts-ignore - process.env exists in Node compat mode
|
||||
globalThis.process.env[key] = stringValue;
|
||||
}
|
||||
|
||||
console.log(` ✅ Set ${key} = ${stringValue.substring(0, 10)}...`);
|
||||
}
|
||||
// Verify they're set
|
||||
// Verify they're set in both places
|
||||
console.log(
|
||||
'🔍 Verification - Deno.env has:',
|
||||
envKeys.map((k) => `${k}=${Deno.env.get(k)?.substring(0, 10)}...`)
|
||||
);
|
||||
// @ts-ignore - process is available in Node.js compatibility mode
|
||||
if (typeof globalThis.process !== 'undefined' && globalThis.process.env) {
|
||||
console.log(
|
||||
'🔍 Verification - process.env has:',
|
||||
// @ts-ignore - process.env exists in Node compat mode
|
||||
envKeys.map((k) => `${k}=${globalThis.process.env[k]?.substring(0, 10)}...`)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log('⚠️ No env vars provided in request');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue