{"id":"390dd5cebf5dca1f","repo":"babel/babel","slug":"name-is-read-only","errorCode":null,"errorMessage":"\"${name}\" is read-only","messagePattern":"\"(.+?)\" is read-only","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/babel-helpers/src/helpers/readOnlyError.ts","lineNumber":4,"sourceCode":"/* @minVersion 7.0.0-beta.0 */\n\nexport default function _readOnlyError(name: string) {\n  throw new TypeError('\"' + name + '\" is read-only');\n}\n","sourceCodeStart":1,"sourceCodeEnd":6,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-helpers/src/helpers/readOnlyError.ts#L1-L6","documentation":"This TypeError is thrown by _readOnlyError(name), emitted by Babel's block-scoping transform when a `const`-declared binding is assigned in source. Because the transform may downlevel `const` to `var` (losing native read-only enforcement), it inserts this helper at assignment sites to preserve the runtime TypeError that `const` would normally produce. The thrown message names the offending binding.","triggerScenarios":"Any assignment to a `const` variable: `const x = 1; x = 2;`, `const cfg = {}; cfg = newCfg;`, `++counter` where counter is const, or compound assignment `x += 1` on a const.","commonSituations":"Accidentally declaring with `const` instead of `let`; refactoring that changes a value's mutation pattern; copy-paste leaving `const` on a variable that needs reassignment; linter disabled so the mistake reaches the transpiler.","solutions":["Change the declaration from `const` to `let` if reassignment is intended.","If the binding should be immutable, fix the logic so it never reassigns (mutate properties instead: `cfg.field = x`).","Enable a linter rule (prefer-const / no-const-assign) to catch this at edit time."],"exampleFix":"// before\nconst total = 0;\nfor (const n of nums) total += n; // throws\n\n// after\nlet total = 0;\nfor (const n of nums) total += n;","handlingStrategy":"validation","validationCode":"// Decide intent before declaring:\n// - need reassignment? use `let`\n// - immutable binding? use `const` and never reassign\nlet total = 0;\ntotal += n;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable ESLint `no-const-assign` to catch this at edit time.","Use `let` whenever the variable will be reassigned.","Mutate object fields rather than rebinding const references."],"tags":["babel-helpers","runtime","const","block-scoping","typeerror"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}