{"record":{"id":"9f7f9e13954f761e","repo":"sveltejs/kit","slug":"file-must-export-a-variables-object","errorCode":null,"errorMessage":"${file} must export a variables object","messagePattern":"(.+?) must export a variables object","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/core/env.js","lineNumber":87,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t]\n\t});\n\n\t/** @type {Record<string, EnvVarConfig<any>>} */\n\tlet variables;\n\n\tconst runner = get_runner(vite, server);\n\n\t/** @type {typeof import('../runtime/app/env/server.js')} */ (\n\t\tawait runner.import(`${runtime_directory}/app/env/server.js`)\n\t).set_building();\n\n\ttry {\n\t\t({ variables } = await runner.import(file));\n\n\t\tif (!variables || typeof variables !== 'object') {\n\t\t\tthrow new Error(`${file} must export a variables object`);\n\t\t}\n\n\t\t// validate\n\t\tfor (const name of Object.keys(variables)) {\n\t\t\tif (!valid_identifier.test(name) || reserved.has(name)) {\n\t\t\t\tthrow new Error(`Invalid environment variable name ${JSON.stringify(name)}`);\n\t\t\t}\n\t\t}\n\t} catch (e) {\n\t\tconst error = /** @type {any} */ (e || {});\n\n\t\tif (\n\t\t\terror.code === 'ERR_MODULE_NOT_FOUND' &&\n\t\t\terror.message?.includes(`Cannot find module '$app`)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot import \\`$app/*\\` modules other than \\`$app/env\\` inside \\`src/env\\``,\n\t\t\t\t{ cause: e }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/core/env.js#L69-L105","documentation":"When a project has a src/env.js (or .ts) file, SvelteKit loads it during build and requires it to export a `variables` object mapping environment variable names to their types. This error is thrown when the module exports nothing, or exports a `variables` that is not an object (e.g. a string, array of entries, or missing entirely).","triggerScenarios":"src/env.js exists but has no `export const variables = {...}`; `variables` is exported as something non-object (string, class instance like an enum, Map); the default export is used instead of a named `variables` export.","commonSituations":"Following old pre-1.0 SvelteKit env documentation; exporting `variables` as a zod schema or enum object (class instance) which fails the plain-object typeof check; typo like `variable` instead of `variables`.","solutions":["Add `export const variables = { MY_VAR: 'string', OTHER: 'boolean' };` to src/env.js.","Ensure `variables` is a plain object literal, not an enum/schema instance, string, or array.","Use the named export `variables` — a default export will not satisfy the check."],"exampleFix":"// before (src/env.js)\nexport default { PUBLIC_KEY: 'string' };\n// after\nexport const variables = { PUBLIC_KEY: 'string' };","handlingStrategy":"validation","validationCode":"// run before build against src/env.js\nconst mod = await import('./src/env.js');\nif (!mod.variables || typeof mod.variables !== 'object' || Array.isArray(mod.variables)) {\n  throw new Error('src/env.js must export a plain `variables` object');\n}","typeGuard":"function hasValidVariablesExport(mod) {\n  return mod !== null && typeof mod === 'object' &&\n    'variables' in mod && typeof mod.variables === 'object' && mod.variables !== null;\n}","tryCatchPattern":"try {\n  await viteBuild();\n} catch (e) {\n  if (String(e.message).includes('must export a variables object')) {\n    console.error('Fix src/env.js: add `export const variables = { NAME: \\'string\\' }`');\n  } else throw e;\n}","preventionTips":["Always use the named export `variables`, never default export, in src/env.js.","Keep variables a plain object literal — avoid enums, Maps, or schema instances.","Run a build after creating src/env.js to validate its shape early."],"tags":["env","config","sveltekit"],"backgroundTag":"invalid-env-declaration","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}