Registry / devops / esbuild-svelte

esbuild-svelte

JSON →
library0.9.4jsnpmunverified

esbuild plugin that resolves and compiles .svelte files for bundling with esbuild. Current stable version 0.9.4, actively maintained. Supports Svelte 4 and 5 (peer dep range >=4.2.1 <6). Key differentiators: zero-config setup for CSS handling (external by default, can inject), built-in caching for incremental builds, and full support for Svelte preprocessors including TypeScript. Compared to alternatives like svelte-loader for webpack or vite-plugin-svelte, this plugin is tailored for esbuild's speed and simplicity, with minimal dependencies and straightforward API.

npm install esbuild-svelte
INSTALL
IMPORT
SIG · ESBUILD-SVELTE
E
esbuild-svelte
devopsjavascriptv0.9.4
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default export (sveltePlugin)
import sveltePlugin from 'esbuild-svelte'
const sveltePlugin = require('esbuild-svelte')
ESM-only; CommonJS require will fail. Also, avoid importing from a subpath like 'esbuild-svelte/plugin'.
sveltePlugin
import sveltePlugin from 'esbuild-svelte'
import { sveltePlugin } from 'esbuild-svelte'
The plugin is a default export, not a named export. Named import will be undefined.
SveltePluginOptions (TypeScript type)
import type { SveltePluginOptions } from 'esbuild-svelte'
import { SveltePluginOptions } from 'esbuild-svelte'
Use 'import type' for type-only imports to avoid runtime issues with ESM.

Shows minimal esbuild build script with sveltePlugin, including required mainFields and conditions for Svelte component resolution.

import esbuild from 'esbuild'; import sveltePlugin from 'esbuild-svelte'; await esbuild.build({ entryPoints: ['src/main.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [sveltePlugin()], mainFields: ['svelte', 'browser', 'module', 'main'], conditions: ['svelte', 'browser'], logLevel: 'info', });
Debug
Known issues
breakingVersion 0.8.0 dropped support for Svelte 3 and Node <18.
fix
Upgrade Svelte to >=4.2.1 and Node to >=18.
affects: >=0.8.0
deprecatedThe 'external' option in plugin options has been deprecated; use compilerOptions.css instead.
fix
Set compilerOptions.css: 'external' to emit external CSS, or 'injected' to include in JS.
affects: >=0.8.0
gotchaMissing 'svelte' in esbuild conditions or mainFields causes resolution failures for Svelte component libraries.
fix
Add 'svelte' to conditions and 'svelte' to mainFields in esbuild build options.
affects: >=0.1.0
gotchaPlugin does not handle HMR or dev server; it's a compile-only plugin.
fix
Use a separate dev server like sirv and configure esbuild in watch mode, or consider vite-plugin-svelte for dev experience.
affects: >=0.1.0
breakingIn version 0.7.0, the default CSS handling changed from 'injected' to 'external'.
fix
Explicitly set compilerOptions.css if default behavior matters.
affects: >=0.7.0 <0.8.0
Errors
Common errors & fixes
Error: No matching export in 'esbuild-svelte' for import 'sveltePlugin'
Incorrect named import instead of default import.
fix
Change to: import sveltePlugin from 'esbuild-svelte';
TypeError: sveltePlugin is not a function
Using CommonJS require which returns a module object instead of the default export.
fix
Use ESM import or use require('esbuild-svelte').default.
Cannot find module 'esbuild-svelte'
Missing dependency or incorrect Node version (<18).
fix
Run 'npm install esbuild-svelte' and ensure Node >=18.
Error: The 'svelte' package must be installed and version >=4.2.1
Missing or outdated peer dependency svelte.
fix
Run 'npm install svelte@^4.2.1'.
Error: '@sveltejs/vite-plugin-svelte' is not compatible with esbuild-svelte
Conflicting plugins; both handle .svelte files.
fix
Remove vite-plugin-svelte from plugins array when using esbuild-svelte.
Upgrade
Version history
0.9.4latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency: required for plugin to function; esbuild >=0.17.0
svelterequiredPeer dependency: required to compile .svelte files; Svelte >=4.2.1 <6
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-svelte — npm install esbuild-svelte · libregistry