esbuild-plugin-elm
raw JSON → 0.0.12 verified Mon Apr 27 auth: no javascript
An esbuild plugin for building Elm projects, version 0.0.12. It integrates the Elm compiler into esbuild's build process, resolving imports via elm.json source-directories. Key features include debug mode, optimization based on NODE_ENV, watch mode support with console clearing, and custom path to Elm executable. Compared to alternatives like elm-webpack-loader or elm-parcel, this plugin is tightly coupled with esbuild, offering faster builds. It depends on esbuild >=0.8.1. Release cadence is irregular, last updated in 2022.
Common errors
error TypeError: ElmPlugin is not a function ↓
cause Incorrect import: const ElmPlugin = require('esbuild-plugin-elm') instead of .default
fix
const ElmPlugin = require('esbuild-plugin-elm').default
error Error: Plugin 'elm' failed: elm: command not found ↓
cause Elm compiler not installed or not in PATH
fix
Install elm globally or set pathToElm option to full path of elm executable
error error: No matching entry point found for 'src/Main.elm' ↓
cause Entry point file extension not recognized; use .js or .ts as entry, not .elm
fix
Use a JavaScript/TypeScript file as entry point that imports Elm modules
Warnings
gotcha Default export; named import fails ↓
fix Use default import: import ElmPlugin from 'esbuild-plugin-elm'
gotcha CommonJS require returns ESM module; must use .default ↓
fix Use const ElmPlugin = require('esbuild-plugin-elm').default
gotcha Path to Elm executable defaults to 'elm' in PATH; may fail if not installed globally ↓
fix Set pathToElm option to exact path of elm binary (e.g., require('elm'))
Install
npm install esbuild-plugin-elm yarn add esbuild-plugin-elm pnpm add esbuild-plugin-elm Imports
- ElmPlugin wrong
const { ElmPlugin } = require('esbuild-plugin-elm')correctimport ElmPlugin from 'esbuild-plugin-elm' - ElmPlugin wrong
const ElmPlugin = require('esbuild-plugin-elm')correctconst ElmPlugin = require('esbuild-plugin-elm').default - ElmPlugin wrong
import { ElmPlugin } from 'esbuild-plugin-elm'correctimport ElmPlugin from 'esbuild-plugin-elm'
Quickstart
import esbuild from 'esbuild';
import ElmPlugin from 'esbuild-plugin-elm';
await esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [
ElmPlugin({
debug: false,
optimize: process.env.NODE_ENV === 'production',
pathToElm: 'node_modules/.bin/elm',
clearOnWatch: false,
verbose: false,
}),
],
});
console.log('Build complete.');