vite-gleam

raw JSON →
1.7.1 verified Mon Apr 27 auth: no javascript

Vite plugin to import Gleam (*.gleam) files directly in JavaScript/TypeScript projects. Current version 1.7.1 targets Vite 5 (Y digit reflects Vite major version, e.g., 1.x.y for Vite 4, 1.7.x for Vite 5). Released actively alongside Gleam ecosystem. Key differentiator: enables seamless integration of Gleam code into Vite builds without separate compilation step.

error Error: Cannot find module 'vite-gleam'
cause Missing installation or wrong import path.
fix
Run npm install vite-gleam (dev dependency) and import using import gleam from 'vite-gleam'.
error Cannot use import statement outside a module
cause Using ESM syntax in a CommonJS context.
fix
Set "type": "module" in package.json or rename file to .mjs.
breaking Breaking change: Vite major version update requires matching vite-gleam major version. Version format X.Y.Z where X is breaking, Y is Vite version, Z is minor.
fix Ensure vite-gleam version's Y digit matches Vite major version (e.g., 1.7.x for Vite 5). Check release notes for breaking changes between X increments.
gotcha TypeScript LSP reports error when importing .gleam files without type declarations.
fix Add `declare module "*.gleam";` in a .d.ts file or use ts-gleam for full type support.
gotcha Plugin must be placed before other plugins that transform imports (like @vitejs/plugin-react).
fix Ensure gleam() is first in the plugins array.
gotcha Gleam compiler must be installed separately; vite-gleam does not include it.
fix Install Gleam (https://gleam.run) and have a gleam.toml in project root.
npm install vite-gleam
yarn add vite-gleam
pnpm add vite-gleam

Install vite-gleam, add plugin to Vite config, then import .gleam files directly.

// vite.config.ts
import { defineConfig } from 'vite';
import gleam from 'vite-gleam';

export default defineConfig({
  plugins: [gleam()],
});