{"id":22897,"library":"vite-plugin-ts-nameof","title":"vite-plugin-ts-nameof","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/Shinigami92/vite-plugin-ts-nameof","tags":["javascript","vite","vite-plugin","ts-nameof","nameof","plugin","typescript","vitejs","awesome"],"install":[{"cmd":"npm install vite-plugin-ts-nameof","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-ts-nameof","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-ts-nameof","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides type definitions for nameof function used in TypeScript code.","package":"@typescript-nameof/common-types","optional":false},{"reason":"Provides global type augmentation for nameof.","package":"@typescript-nameof/types","optional":false},{"reason":"Peer dependency; plugin requires Vite ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0.","package":"vite","optional":false}],"imports":[{"note":"ESM-only; CommonJS require will fail.","wrong":"const tsNameof = require('vite-plugin-ts-nameof')","symbol":"default (tsNameof)","correct":"import tsNameof from 'vite-plugin-ts-nameof'"},{"note":"Named export is also available, but default import is preferred.","wrong":"import { tsNameof } from 'vite-plugin-ts-nameof/index.js'","symbol":"tsNameof (named)","correct":"import { tsNameof } from 'vite-plugin-ts-nameof'"},{"note":"nameof is not exported by the plugin; it's a global type provided by @typescript-nameof/types.","wrong":"import { nameof } from 'vite-plugin-ts-nameof'","symbol":"nameof","correct":"// global type definition imported via tsconfig files; // no import needed at runtime, just use nameof() in TS"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport tsNameof from 'vite-plugin-ts-nameof';\n\nexport default defineConfig({\n  plugins: [tsNameof()],\n});\n\n// tsconfig.json (add files array)\n{\n  \"compilerOptions\": { ... },\n  \"files\": [\"./node_modules/@typescript-nameof/types/index.d.cts\"]\n}\n\n// In your TS code:\nclass MyClass {\n  myMethod() {}\n}\nconst methodName: string = nameof<MyClass>(x => x.myMethod); // resolves to \"myMethod\"\nconsole.log(methodName); // \"myMethod\"","lang":"typescript","description":"Add the plugin to Vite config and configure tsconfig to enable nameof calls."},"warnings":[{"fix":"Update @typescript-nameof/common-types to latest compatible version or remove if not needed.","message":"The peer dependency @typescript-nameof/common-types version '^0.0.7' is deprecated; consider pinning to exact version or checking for updates.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Use the TypeScript language service plugin or a separate transform for IDE support.","message":"The plugin is only active during Vite's serve and build; it will not transform code in IDEs or other environments.","severity":"gotcha","affected_versions":">=3.0.0"},{"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.","message":"nameof is a compile-time transformation; the nameof variable is not available at runtime. Ensure you are not calling nameof in a dynamic context.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure your Vite version matches one of the supported major versions.","message":"The 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.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"If migrating from v2, check the plugin options and update Vite to >=2.0.0.","message":"Version 3.0.0 drops support for Vite 1.x and may have incompatible internal changes from v2.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add './node_modules/@typescript-nameof/types/index.d.cts' to the 'files' array in tsconfig.json.","cause":"Missing global type declaration from @typescript-nameof/types.","error":"Cannot find name 'nameof'."},{"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.","cause":"Vite is not using the plugin or the plugin is misconfigured.","error":"Error: Transform failed with error: Unexpected token 'nameof'"},{"fix":"Change require to import: import tsNameof from 'vite-plugin-ts-nameof'.","cause":"Using CommonJS require instead of ESM import.","error":"TypeError: tsNameof is not a function"},{"fix":"Install the missing peer dependency: npm add --save-dev @typescript-nameof/common-types.","cause":"Missing dev dependency @typescript-nameof/common-types.","error":"Module not found: Can't resolve '@typescript-nameof/common-types'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}