{"record":{"id":"857ab1f05c38e765","repo":"parcel-bundler/parcel","slug":"cannot-change-an-asset-s-uniquekey-after-it-has-be","errorCode":null,"errorMessage":"Cannot change an asset's uniqueKey after it has been set.","messagePattern":"Cannot change an asset's uniqueKey after it has been set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/public/Asset.js","lineNumber":286,"sourceCode":"  set isBundleSplittable(isBundleSplittable: boolean): void {\n    this.#asset.value.isBundleSplittable = isBundleSplittable;\n  }\n\n  get sideEffects(): boolean {\n    return this.#asset.value.sideEffects;\n  }\n\n  set sideEffects(sideEffects: boolean): void {\n    this.#asset.value.sideEffects = sideEffects;\n  }\n\n  get uniqueKey(): ?string {\n    return this.#asset.value.uniqueKey;\n  }\n\n  set uniqueKey(uniqueKey: ?string): void {\n    if (this.#asset.value.uniqueKey != null) {\n      throw new Error(\n        \"Cannot change an asset's uniqueKey after it has been set.\",\n      );\n    }\n    this.#asset.value.uniqueKey = uniqueKey;\n  }\n\n  get symbols(): IMutableAssetSymbols {\n    return new MutableAssetSymbols(this.#asset.options, this.#asset.value);\n  }\n\n  addDependency(dep: DependencyOptions): string {\n    return this.#asset.addDependency(dep);\n  }\n\n  invalidateOnFileChange(filePath: FilePath): void {\n    this.#asset.invalidateOnFileChange(\n      toProjectPath(this.#asset.options.projectRoot, filePath),\n    );","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/public/Asset.js#L268-L304","documentation":"`uniqueKey` is the asset's stable cache identity. It is write-once: once assigned (non-null), subsequent assignments are rejected because changing it would invalidate cached outputs and corrupt dependency resolution. The setter checks the current value and throws if it is already set.","triggerScenarios":"A transformer calls `asset.uniqueKey = '...'` on an asset that already has a non-null `uniqueKey`.","commonSituations":"A transformer that sets uniqueKey on every pass; code that copies/merges assets and reassigns the key; running a transformer twice over the same asset.","solutions":["Check `asset.uniqueKey == null` before assigning.","Compute the key once (e.g. at asset creation) and reuse it.","If you need a different identity, create a new asset instead of mutating the existing one."],"exampleFix":"// before\nasset.uniqueKey = computeKey(); // throws on second pass\n\n// after\nif (asset.uniqueKey == null) asset.uniqueKey = computeKey();","handlingStrategy":"validation","validationCode":"// Only assign uniqueKey when it is unset.\nif (asset.value.uniqueKey == null) {\n  asset.value.uniqueKey = computeKey();\n}","typeGuard":"function canSetUniqueKey(asset: {value: {uniqueKey?: ?string}}): boolean {\n  return asset.value.uniqueKey == null;\n}","tryCatchPattern":null,"preventionTips":["Set uniqueKey exactly once, ideally at asset creation.","Never reassign across transformer passes; create a new asset instead.","Guard every assignment site with a null check."],"tags":["asset","transformer","cache","immutability"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}