Registry / web-framework / vite-plugin-relay

vite-plugin-relay

JSON →
library2.1.0jsnpmunverified

A Vite plugin that integrates Relay (GraphQL) into Vite projects. Current stable version is 2.1.0, with periodic maintenance updates. It internally invokes babel-plugin-relay to transform GraphQL artifacts, ensuring compatibility with Relay's official toolchain. Key differentiators: zero-config setup (relay config auto-detected from package.json or relay.config.*), supports Vite 2+ and 3, pnpm-friendly, and ESM-first. The plugin handles babel-plugin-relay invocation, so developers skip its direct configuration. Maintenance is periodic as the author is not actively using the project.

npm install vite-plugin-relay
INSTALL
IMPORT
SIG · VITE-PLUGIN-RELAY
V
vite-plugin-relay
web-frameworkjavascriptv2.1.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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

relay
import relay from 'vite-plugin-relay'
const { relay } = require('vite-plugin-relay')
Default export only; package is ESM-only and requires static import.
ViteRelayPluginOptions
import type { ViteRelayPluginOptions } from 'vite-plugin-relay'
TypeScript type available for plugin configuration options (empty object by default).
relay (in vitest)
import relay from 'vite-plugin-relay'
import { relay } from 'vite-plugin-relay'
When using with Vitest, must use default import. Named import will fail.

Minimal Vite config to add Relay support. Must also have relay.config.json or similar.

// vite.config.ts import { defineConfig } from 'vite'; import relay from 'vite-plugin-relay'; export default defineConfig({ plugins: [relay], });
Debug
Known issues
breakingv2.0.0 removed the automatic globalThis polyfill for window. If window is not defined (e.g., SSR), add the manual polyfill shown in Common Issues.
fix
Add snippet: if (typeof (window as any).global === 'undefined') {(window as any).global = globalThis;}
affects: >=2.0.0
deprecatedv1.0.7 removed the redefinition of global window property. Users on older versions may need to add it back.
fix
Update to >=1.0.7 or add window polyfill manually.
affects: <1.0.7
gotchaUncaught ReferenceError: global is not defined in browser. Occurs when global is not set (common with bundlers).
fix
Add <script>let global = globalThis;</script> in index.html before your JS.
affects: *
gotchaMust install babel-plugin-relay as devDependency, but DO NOT add it to vite config. The plugin invokes it automatically.
fix
Install babel-plugin-relay (>=13.0.1) as devDependency. Skip babel config in vite/relay plugin.
affects: *
gotcharelay-compiler must output ESM artifacts (eagerEsModules: true) in relay config. Without this, plugin may fail to detect graphql tags.
fix
Set eagerEsModules: true in relay.config.json or package.json relay field.
affects: *
Errors
Common errors & fixes
ReferenceError: global is not defined
Missing global polyfill when using vite-plugin-relay in a browser environment (e.g., React app).
fix
Add to index.html: <script>let global = globalThis;</script> before importing your application JS.
Module '"vite-plugin-relay"' has no exported member 'relay'
Using named import instead of default import.
fix
Use: import relay from 'vite-plugin-relay'
Cannot find module 'babel-plugin-relay' or 'babel-plugin-relay' is not installed
Missing required peer dependency.
fix
Install babel-plugin-relay: npm install --save-dev babel-plugin-relay
Expected relay config to have eagerEsModules: true
relay-compiler not configured to output ESM artifacts.
fix
Set eagerEsModules: true in relay config file (relay.config.json or package.json relay field).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
babel-plugin-relayrequiredPeer dependency that provides the actual Relay GraphQL transformation; must be >=13.0.1, recommended >=14.1.0 for v2.1.0
viterequiredPeer dependency; must be >=2.0.0 (Vite 2 or 3)
Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
vite-plugin-relay — npm install vite-plugin-relay · libregistry