Skip to content

ecs-persistence: [persist] on an app's components fails to compile (trait key from a package's types is 'unique symbol') #239

Closed as not planned

Description

@krisnye

Summary

An app can't mark its components with [persist] as the @adobe/ecs-persistence README shows. With Compiler.plugin() the build fails:

a trait's key persist is a top-level `Symbol()` constant, of this module or one it imports
  [baseColorFactor]: { type: Vec4.F32; default: [1, 1, 1, 1]; [persist]: 'baseColorFactor' };

Repro

import { persist } from '@adobe/ecs-persistence';
export const name = Symbol();
declare module '@adobe/ecs' {
    interface Components {
        [name]: { type: string; [persist]: 'name' };
    }
}

Built with @adobe/ecs 0.2.3, @adobe/ecs-persistence 0.0.1, Vite 8 and Compiler.plugin(), in the dev server, a build and vitest alike.

Cause

The compiler reads a trait key's declaration to check that it is a Symbol() constant (requireTraitKey, augmentations.ts). For an import from a package it reads the types file beside the JavaScript (typesFileOf), and in dist/types/persist.d.ts the key is export declare const persist: unique symbol;, which is not a Symbol() call. The special case that finds a package's source applies to copies of @adobe/ecs itself, not to other packages.

Workaround

Alias @adobe/ecs-persistence to the src/index.ts the package already ships (resolve.alias), and keep it out of the dev server's pre-bundling (optimizeDeps.exclude); under vitest it also needs to be transformed by the plugin. That works but every app has to know to do it.

Requested (any of)

  1. The compiler accepts a trait key whose declaration is declare const x: unique symbol in an imported package's types, since the key's identity is registered at runtime by the package's own JavaScript (declare$(persist, "trait")).
  2. The compiler finds the source a package ships, as it does for @adobe/ecs, for any package that declares traits.
  3. @adobe/ecs-persistence documents what an app must configure, and ships it as a Vite helper.

Activity

  1. krisnye commented on Nov 1, 2026

    @krisnye
    CollaboratorAuthor

    @adobe/ecs-persistence 0.1.0 declares no trait of its own (#241, in #240): an app declares its own, snapshot({ world, by }), so no package's unique symbol trait key is named in an app's declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions