{"record":{"id":"0528177ad68fdb7c","repo":"vitejs/vite","slug":"invalid-environment-name-name-environment-na","errorCode":null,"errorMessage":"Invalid environment name \"${name}\". Environment names must only contain alphanumeric characters and \"$\", \"_\".","messagePattern":"Invalid environment name \"(.+?)\"\\. Environment names must only contain alphanumeric characters and \"\\$\", \"_\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/baseEnvironment.ts","lineNumber":40,"sourceCode":"\n  /**\n   * @internal\n   */\n  _options: ResolvedEnvironmentOptions\n  /**\n   * @internal\n   */\n  _topLevelConfig: ResolvedConfig\n\n  constructor(\n    name: string,\n    topLevelConfig: ResolvedConfig,\n    options: ResolvedEnvironmentOptions = topLevelConfig.environments[name],\n  ) {\n    // only allow some characters so that we can use name without escaping for directory names\n    // and make users easier to access with `environments.*`\n    if (!/^[\\w$]+$/.test(name)) {\n      throw new Error(\n        `Invalid environment name \"${name}\". Environment names must only contain alphanumeric characters and \"$\", \"_\".`,\n      )\n    }\n    this.name = name\n    this._topLevelConfig = topLevelConfig\n    this._options = options\n    this.config = new Proxy(\n      options as ResolvedConfig & ResolvedEnvironmentOptions,\n      {\n        get: (target, prop: keyof ResolvedConfig) => {\n          if (prop === 'logger') {\n            return this.logger\n          }\n          if (prop in target) {\n            return this._options[prop as keyof ResolvedEnvironmentOptions]\n          }\n          return this._topLevelConfig[prop]\n        },","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/baseEnvironment.ts#L22-L58","documentation":"When constructing an environment, the base environment constructor validates the name against `/^[\\w$]+$/` (alphanumeric, underscore, dollar only). Names are used unescaped as directory names and accessed via `environments.<name>`, so characters like `-`, `.`, `/`, or spaces are rejected to keep filesystem and config access safe.","triggerScenarios":"Creating an environment with a name containing a dash, dot, slash, space, or any non-word character - e.g. defining `environments: { 'my-env': {...} }` or calling `createEnvironment('ssr.client', ...)`.","commonSituations":"Naming environments with kebab-case (`my-env`) instead of camelCase/underscore. Deriving environment names from URLs or file paths. Copying env var names (often dashed) as environment keys.","solutions":["Rename the environment to use only `[A-Za-z0-9_$]` - e.g. `myEnv` or `my_env` instead of `my-env`.","If the name comes from user input, sanitize it: `name.replace(/[^\\w$]/g, '_')`.","Use the conventional names `client` and `ssr` unless you need custom environments."],"exampleFix":"// before\nenvironments: { 'ssr-server': { ... } }\n// after\nenvironments: { ssrServer: { ... } }","handlingStrategy":"validation","validationCode":"function assertValidEnvironmentName(name: string) {\n  if (!/^[\\w$]+$/.test(name)) {\n    throw new Error(`Invalid environment name \"${name}\". Use only [A-Za-z0-9_$].`)\n  }\n}","typeGuard":"function isValidEnvironmentName(name: string): boolean {\n  return /^[\\w$]+$/.test(name)\n}","tryCatchPattern":null,"preventionTips":["Use camelCase or snake_case for environment names; never kebab-case or dotted names.","If names come from external input, sanitize with name.replace(/[^\\w$]/g, '_')."],"tags":["environments","config-validation","naming","vite-6"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}