parcel-bundler/parcel · error · Error
Cannot change an asset's uniqueKey after it has been set.
Error message
Cannot change an asset's uniqueKey after it has been set.
What it means
`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.
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.
Example fix
// before asset.uniqueKey = computeKey(); // throws on second pass // after if (asset.uniqueKey == null) asset.uniqueKey = computeKey();
Defensive patterns
Strategy: validation
Validate before calling
// Only assign uniqueKey when it is unset.
if (asset.value.uniqueKey == null) {
asset.value.uniqueKey = computeKey();
} Type guard
function canSetUniqueKey(asset: {value: {uniqueKey?: ?string}}): boolean {
return asset.value.uniqueKey == null;
} Prevention
- 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.
When it happens
Trigger: A transformer calls `asset.uniqueKey = '...'` on an asset that already has a non-null `uniqueKey`.
Common situations: 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.
Related errors
- Cannot call getCode() on an asset with a dirty AST. For…
- Asset has an AST but no generate method is available on the…
- Config result is not hashable because it contains…
- failed to locate file
- IDBCache is only supported in the browser
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/857ab1f05c38e765.
Report an issue: GitHub.
Appendix: source
Thrown at packages/core/core/src/public/Asset.js:286
set isBundleSplittable(isBundleSplittable: boolean): void {
this.#asset.value.isBundleSplittable = isBundleSplittable;
}
get sideEffects(): boolean {
return this.#asset.value.sideEffects;
}
set sideEffects(sideEffects: boolean): void {
this.#asset.value.sideEffects = sideEffects;
}
get uniqueKey(): ?string {
return this.#asset.value.uniqueKey;
}
set uniqueKey(uniqueKey: ?string): void {
if (this.#asset.value.uniqueKey != null) {
throw new Error(
"Cannot change an asset's uniqueKey after it has been set.",
);
}
this.#asset.value.uniqueKey = uniqueKey;
}
get symbols(): IMutableAssetSymbols {
return new MutableAssetSymbols(this.#asset.options, this.#asset.value);
}
addDependency(dep: DependencyOptions): string {
return this.#asset.addDependency(dep);
}
invalidateOnFileChange(filePath: FilePath): void {
this.#asset.invalidateOnFileChange(
toProjectPath(this.#asset.options.projectRoot, filePath),
);View on GitHub (pinned to 59484858a1)