Registry /
web-framework / vite-plugin-graphql-codegen
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
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import codegen from 'vite-plugin-graphql-codegen'
✗ const codegen = require('vite-plugin-graphql-codegen')
Default export; CommonJS require works in CJS environments but ESM is recommended for Vite plugin usage.
vitePluginGraphqlCodegen
✓ import { vitePluginGraphqlCodegen } from 'vite-plugin-graphql-codegen'
✗ import codegen from 'vite-plugin-graphql-codegen/vitePluginGraphqlCodegen'
Named export available as an alternative to default; useful for explicit named imports.
PluginOptions
✓ import type { PluginOptions } from 'vite-plugin-graphql-codegen'
✗ import { PluginOptions } from 'vite-plugin-graphql-codegen'
TypeScript only - import type to avoid runtime inclusion. PluginOptions is not a value export.
Basic setup of vite-plugin-graphql-codegen in vite.config.ts with config override and conditional skip.
// vite.config.ts
import { defineConfig } from 'vite';
import codegen from 'vite-plugin-graphql-codegen';
export default defineConfig({
plugins: [
codegen({
// Optional: override codegen config for specific triggers
configOverrideOnStart: {
generates: {
'src/generated/graphql.ts': {
documents: './src/**/*.graphql',
schema: 'https://api.example.com/graphql',
plugins: ['typescript', 'typescript-operations'],
},
},
},
// Skip codegen during CI build
skip: (context) => context.trigger === 'build' && process.env.CI === 'true',
}),
],
});
Errors
Common errors & fixes
Cannot find module 'vite-plugin-graphql-codegen' or its corresponding type declarations.
Plugin not installed or missing peer dependencies.
fixRun npm install vite-plugin-graphql-codegen @graphql-codegen/cli graphql vite
Error: @graphql-codegen/cli version 5 is not supported. Please upgrade to >=6.0.0.
v3.7.0+ requires @graphql-codegen/cli v6 or later.
fixRun npm install @graphql-codegen/cli@latest
TypeError: codegen is not a function
Importing the plugin incorrectly (e.g., using named import instead of default).
fixUse import codegen from 'vite-plugin-graphql-codegen' instead of { codegen }. Error: GraphQL Code Generator failed with 1 error(s). TypeScript errors found.
Codegen configuration (schema, documents, or plugins) are misconfigured.
fixCheck your codegen.yml or configOverride for errors, ensure schema URL is reachable and documents pattern matches files.
Audit
Dependencies
@graphql-codegen/clirequiredPeer dependency - core codegen library that handles code generation logic
graphqlrequiredPeer dependency - required by @graphql-codegen/cli for parsing and executing GraphQL operations
viterequiredPeer dependency - plugin only works within a Vite project, provides dev server and build hooks