{"record":{"id":"957c8f8285e4d584","repo":"denoland/deno","slug":"cannot-convert-a-symbol-value-to-a-string","errorCode":null,"errorMessage":"Cannot convert a Symbol value to a string","messagePattern":"Cannot convert a Symbol value to a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_process/process.ts","lineNumber":144,"sourceCode":"\n      return envValue;\n    },\n    ownKeys: () => ReflectOwnKeys(Deno.env.toObject()),\n    getOwnPropertyDescriptor: (_target, name) => {\n      const value = denoEnvGet(String(name));\n      if (value !== undefined) {\n        return {\n          __proto__: null,\n          enumerable: true,\n          configurable: true,\n          value,\n        };\n      }\n    },\n    set(_target, prop, value) {\n      // Match Node: v8 ToString on a symbol key or value throws TypeError.\n      if (typeof prop === \"symbol\" || typeof value === \"symbol\") {\n        throw new TypeError(\"Cannot convert a Symbol value to a string\");\n      }\n\n      if (typeof value !== \"string\") {\n        nodeProcess ??= loadProcess();\n        nodeProcess.emitWarning(\n          \"Assigning any value other than a string, number, or boolean to a \" +\n            \"process.env property is deprecated. Please make sure to convert the value \" +\n            \"to a string before setting process.env with it.\",\n          \"DeprecationWarning\",\n          \"DEP0104\",\n        );\n      }\n\n      Deno.env.set(String(prop), String(value));\n      return true; // success\n    },\n    has: (target, prop) => {\n      if (typeof prop === \"symbol\") {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_process/process.ts#L126-L162","documentation":"process.env is a Proxy whose set trap mimics V8 semantics: assigning with a symbol key or a symbol value forces ToString on a symbol, which throws TypeError('Cannot convert a Symbol value to a string'). Non-string, non-symbol values only trigger the DEP0104 deprecation warning; symbols are the one hard failure.","triggerScenarios":"process.env[Symbol('KEY')] = 'x'; process.env.KEY = Symbol('value'); Reflect.set(process.env, sym, 'v'); generic copy loops that write every Reflect.ownKeys() entry (including symbols) into process.env.","commonSituations":"Libraries that enumerate objects with Reflect.ownKeys and copy them into env; constant tables keyed by symbols; test doubles assigning symbol-valued properties; metaprogramming that forwards descriptors onto process.env.","solutions":["Filter out symbol keys and values when copying objects into process.env","Convert values with String(v) for non-symbols (accepting the DEP0104 warning) and skip symbols","Keep env writes at the process boundary; pass typed config objects internally","Audit generic assignment proxies that target process.env"],"exampleFix":"// before\nfor (const key of Reflect.ownKeys(userEnv)) {\n  process.env[key] = userEnv[key]; // symbol key throws\n}\n\n// after\nfor (const key of Reflect.ownKeys(userEnv)) {\n  if (typeof key === 'symbol') continue;\n  const v = userEnv[key];\n  if (typeof v === 'symbol') continue;\n  process.env[key] = String(v);\n}","handlingStrategy":"type-guard","validationCode":"function setEnv(key, value) {\n  if (typeof key === 'symbol' || typeof value === 'symbol') return false;\n  process.env[key] = String(value);\n  return true;\n}","typeGuard":"const isEnvWritable = (k, v) => typeof k !== 'symbol' && typeof v !== 'symbol';","tryCatchPattern":"try {\n  process.env[k] = v;\n} catch (e) {\n  if (e instanceof TypeError && /Symbol/.test(e.message)) {\n    // skip symbol keys/values when copying\n  } else throw e;\n}","preventionTips":["Use Reflect.ownKeys and skip symbols when copying objects into env","Never point generic assignment proxies at process.env","Stringify env values at the edge and keep symbols in-process"],"tags":["process","env","symbols","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}