Registry / web-framework / esbuild-plugin-relay

esbuild-plugin-relay

JSON →
library0.1.0jsnpmunverified

An esbuild plugin that transforms tagged GraphQL template literals for Relay by replacing them with imports to pre-compiled artifacts. Version 0.1.0, pre-release, with no fixed release cadence. Key differentiators: supports esbuild's fast builds, works with TypeScript and both CommonJS/ESM. Caveat: uses string replacement (no AST parsing), so it may process commented-out GraphQL literals.

npm install esbuild-plugin-relay
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-REL
E
esbuild-plugin-relay
web-frameworkjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default (relay)
✓ import relay from 'esbuild-plugin-relay'
✗ const relay = require('esbuild-plugin-relay').default
Default import is the plugin factory function.
Plugin type
✓ import type { Plugin } from 'esbuild'
For TypeScript projects, use esbuild's Plugin type for the plugin object.
No named exports
✓ import relay from 'esbuild-plugin-relay'
The package only has a default export. Named imports like { relay } will fail.

Shows how to configure the relay plugin with esbuild, specifying artifact directory and language.

import esbuild from 'esbuild'; import relay from 'esbuild-plugin-relay'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outdir: 'dist', plugins: [relay({ artifactDirectory: '__generated__', language: 'typescript' })], });
Debug
Known issues
gotchaPlugin does not parse source AST; it replaces all occurrences of graphql`...` strings, including those in comments or strings.
fix
Ensure no commented-out GraphQL literals exist, or use a babel-based approach for AST-aware transforms.
affects: >=0.1.0
deprecatedThe 'language' option may be removed in future versions. Prefer 'module' option for specifying module system.
fix
Use module: 'commonjs' or module: 'esm' instead of language option.
affects: >=0.1.0
gotchaRequires relay-compiler to be run first to generate artifacts; plugin only replaces graphql literals with imports.
fix
Run relay-compiler before esbuild build, and ensure artifact directory matches option.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'esbuild-plugin-relay'
Package not installed or missing from node_modules.
fix
Run npm install -D esbuild-plugin-relay graphql esbuild
Error: graphql is not a function / graphql tagged template literal not transformed
graphql tag from 'graphql' package is being used instead of being replaced. Plugin not loaded or configured incorrectly.
fix
Ensure relay() plugin is added to esbuild plugins array and relay-compiler artifacts exist.
TypeError: relay is not a function
Default import used incorrectly; possibly using require() without .default.
fix
Use import relay from 'esbuild-plugin-relay' or const relay = require('esbuild-plugin-relay').default
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for GraphQL types during artifact generation
esbuildrequiredpeer dependency; the plugin integrates with esbuild's build process
Agent activity
6 hits · last 30 days
node
6
Resources
esbuild-plugin-relay — npm install esbuild-plugin-relay · libregistry