Registry / type-stubs / vite-plugin-ts-nameof

vite-plugin-ts-nameof

JSON →
library3.0.0jsnpmunverified

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-nameof
INSTALL
IMPORT
SIG · VITE-PLUGIN-TS-NAM
V
vite-plugin-ts-nameof
type-stubsjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (tsNameof)
import tsNameof from 'vite-plugin-ts-nameof'
const tsNameof = require('vite-plugin-ts-nameof')
ESM-only; CommonJS require will fail.
tsNameof (named)
import { tsNameof } from 'vite-plugin-ts-nameof'
import { tsNameof } from 'vite-plugin-ts-nameof/index.js'
Named export is also available, but default import is preferred.
nameof
// global type definition imported via tsconfig files; // no import needed at runtime, just use nameof() in TS
import { nameof } from 'vite-plugin-ts-nameof'
nameof is not exported by the plugin; it's a global type provided by @typescript-nameof/types.

Add the plugin to Vite config and configure tsconfig to enable nameof calls.

// vite.config.ts import { defineConfig } from 'vite'; import tsNameof from 'vite-plugin-ts-nameof'; export default defineConfig({ plugins: [tsNameof()], }); // tsconfig.json (add files array) { "compilerOptions": { ... }, "files": ["./node_modules/@typescript-nameof/types/index.d.cts"] } // In your TS code: class MyClass { myMethod() {} } const methodName: string = nameof<MyClass>(x => x.myMethod); // resolves to "myMethod" console.log(methodName); // "myMethod"
Debug
Known issues
deprecatedThe peer dependency @typescript-nameof/common-types version '^0.0.7' is deprecated; consider pinning to exact version or checking for updates.
fix
Update @typescript-nameof/common-types to latest compatible version or remove if not needed.
affects: >=3.0.0
gotchaThe plugin is only active during Vite's serve and build; it will not transform code in IDEs or other environments.
fix
Use the TypeScript language service plugin or a separate transform for IDE support.
affects: >=3.0.0
gotchanameof is a compile-time transformation; the nameof variable is not available at runtime. Ensure you are not calling nameof in a dynamic context.
fix
Only use nameof at the top level or within a function body that will be tree-shaken; do not assign nameof to a variable.
affects: >=3.0.0
gotchaThe plugin relies on a specific version range of Vite (^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0). Using an unsupported Vite version will cause errors.
fix
Ensure your Vite version matches one of the supported major versions.
affects: >=3.0.0
breakingVersion 3.0.0 drops support for Vite 1.x and may have incompatible internal changes from v2.
fix
If migrating from v2, check the plugin options and update Vite to >=2.0.0.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find name 'nameof'.
Missing global type declaration from @typescript-nameof/types.
fix
Add './node_modules/@typescript-nameof/types/index.d.cts' to the 'files' array in tsconfig.json.
Error: Transform failed with error: Unexpected token 'nameof'
Vite is not using the plugin or the plugin is misconfigured.
fix
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.
TypeError: tsNameof is not a function
Using CommonJS require instead of ESM import.
fix
Change require to import: import tsNameof from 'vite-plugin-ts-nameof'.
Module not found: Can't resolve '@typescript-nameof/common-types'
Missing dev dependency @typescript-nameof/common-types.
fix
Install the missing peer dependency: npm add --save-dev @typescript-nameof/common-types.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
@typescript-nameof/common-typesrequiredProvides type definitions for nameof function used in TypeScript code.
@typescript-nameof/typesrequiredProvides global type augmentation for nameof.
viterequiredPeer dependency; plugin requires Vite ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0.
Agent activity
33 hits · last 30 days
node
28
OpenAI (training)
1
Resources
vite-plugin-ts-nameof — npm install vite-plugin-ts-nameof · libregistry