Vite plugin that resolves nameof calls (e.g., nameof(MyClass)) at build time, providing type-safe string references to member names. v3.0.0 supports Vite 2–5 and ships TypeScript types. Requires peer dependencies @typescript-nameof/common-types and @typescript-nameof/types. Alternative to babel-plugin-ts-nameof for Vite-based workflows.
npm install vite-plugin-ts-nameofVerified import paths — ran on the pinned version, not inferred.
Add the plugin to Vite config and configure tsconfig to enable nameof calls.
Update @typescript-nameof/common-types to latest compatible version or remove if not needed.
Use the TypeScript language service plugin or a separate transform for IDE support.
Only use nameof at the top level or within a function body that will be tree-shaken; do not assign nameof to a variable.
Ensure your Vite version matches one of the supported major versions.
If migrating from v2, check the plugin options and update Vite to >=2.0.0.
Add './node_modules/@typescript-nameof/types/index.d.cts' to the 'files' array in tsconfig.json.
Ensure vite-plugin-ts-nameof is added to the plugins array in vite.config.ts and that the plugin comes before other plugins if needed.
Change require to import: import tsNameof from 'vite-plugin-ts-nameof'.
Install the missing peer dependency: npm add --save-dev @typescript-nameof/common-types.