{"record":{"id":"aa5662e29cdc3e53","repo":"vuejs/vuex","slug":"vuex-state-field-modulename-was-overridden","errorCode":null,"errorMessage":"[vuex] state field \"${moduleName}\" was overridden by a module with the same name at \"${path.join('.')}\"","messagePattern":"\\[vuex\\] state field \"(.+?)\" was overridden by a module with the same name at \"(.+?)\"","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/store-util.js","lineNumber":108,"sourceCode":"  const isRoot = !path.length\n  const namespace = store._modules.getNamespace(path)\n\n  // register in namespace map\n  if (module.namespaced) {\n    if (store._modulesNamespaceMap[namespace] && __DEV__) {\n      console.error(`[vuex] duplicate namespace ${namespace} for the namespaced module ${path.join('/')}`)\n    }\n    store._modulesNamespaceMap[namespace] = module\n  }\n\n  // set state\n  if (!isRoot && !hot) {\n    const parentState = getNestedState(rootState, path.slice(0, -1))\n    const moduleName = path[path.length - 1]\n    store._withCommit(() => {\n      if (__DEV__) {\n        if (moduleName in parentState) {\n          console.warn(\n            `[vuex] state field \"${moduleName}\" was overridden by a module with the same name at \"${path.join('.')}\"`\n          )\n        }\n      }\n      parentState[moduleName] = module.state\n    })\n  }\n\n  const local = module.context = makeLocalContext(store, namespace, path)\n\n  module.forEachMutation((mutation, key) => {\n    const namespacedType = namespace + key\n    registerMutation(store, namespacedType, mutation, local)\n  })\n\n  module.forEachAction((action, key) => {\n    const type = action.root ? key : namespace + key\n    const handler = action.handler || action","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/vuejs/vuex/blob/bd907467b8392d6671bb115738285ff7f63d0cf6/src/store-util.js#L90-L126","documentation":"When registering a non-root module, Vuex writes module.state into the parent state object under the module name. If a property with that name already exists on parent state (e.g. defined in the root module's state), the module silently overrides it and Vuex warns in development.","triggerScenarios":"registerModule('foo', ...) or a nested module 'foo' in the modules tree while the parent module's state already declares a 'foo' key.","commonSituations":"Refactoring from flat root state to modules without removing the old root state key; name collision between a state field and a module name; code splitting registers a module whose name collides with existing state.","solutions":["Rename the module (and its registration path) to a non-conflicting key","Remove the duplicate state field from the parent module's state function","Access the module state via the module path and delete any legacy reference","If intentional, silence is not offered — restructure to avoid collision"],"exampleFix":"// before\nconst store = createStore({ state: () => ({ cart: null }), modules: { cart: cartModule } })\n// after\nconst store = createStore({ state: () => ({}), modules: { cart: cartModule } })","handlingStrategy":"validation","validationCode":"function assertNoStateCollision(parentModuleDef, moduleName) {\n  const state = typeof parentModuleDef.state === 'function' ? parentModuleDef.state() : parentModuleDef.state || {}\n  if (moduleName in state) throw new Error(`rename module '${moduleName}' or remove duplicate state field`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid mixing legacy flat root state keys with identically-named modules","Name dynamic modules with a unique prefix","Add a dev-only test asserting no console.warn during store construction"],"tags":["vuex","module-registration","state-collision","dev-warning"],"backgroundTag":"state-key-overridden","analyzedSha":"bd907467b8392d6671bb115738285ff7f63d0cf6","analyzedAt":"2026-08-28T21:38:57.320Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}