esbuild-serve
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
A lightweight wrapper around esbuild that adds a static file server with live reload functionality. Version 1.0.1 is the latest stable release. It is ideal for development workflows where you want esbuild's fast build times combined with automatic browser refreshes on file changes. Unlike heavier alternatives like webpack-dev-server, esbuild-serve has a minimal dependency footprint and focuses solely on serving static files with live reload via esbuild's watch mode. It wraps the ultralight 'serve' HTTP server and requires no complex configuration.
Common errors
error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'esbuild-serve' ↓
cause Missing or incorrect dependency installation; possibly missing from package.json or not in node_modules.
fix
Run 'npm install esbuild-serve --save-dev' (or --save) to install the package.
error TypeError: esbuildServe is not a function ↓
cause Using named import syntax (import { esbuildServe } from 'esbuild-serve') instead of default import.
fix
Change to default import: import esbuildServe from 'esbuild-serve'
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ↓
cause Trying to use require() to load an ESM-only package.
fix
Use import syntax instead of require. Ensure your project is configured for ESM (e.g., type: 'module' in package.json).
Warnings
gotcha esbuild-serve relies on esbuild's watch mode, which will rebundle on file changes but may not trigger livereload if the output file does not change (e.g., errors during rebuild). ↓
fix Ensure your esbuild configuration outputs a file that changes on every successful rebuild. Consider using a placeholder comment.
breaking The serve options object is optional; if omitted, default serve options are used. However, if you pass an empty object, it may override defaults unexpectedly. ↓
fix Either omit the serve options argument entirely or provide all desired options explicitly.
deprecated The package currently uses the 'serve' library by the same author. Future versions might replace it with a different server; stay updated. ↓
fix Monitor the package's GitHub releases for migration notes.
Install
npm install esbuild-serve yarn add esbuild-serve pnpm add esbuild-serve Imports
- esbuildServe wrong
const esbuildServe = require('esbuild-serve');correctimport esbuildServe from 'esbuild-serve'; - default import wrong
import { esbuildServe } from 'esbuild-serve';correctimport esbuildServe from 'esbuild-serve'; - TypeScript usage wrong
import esbuildServe = require('esbuild-serve');correctimport esbuildServe from 'esbuild-serve';
Quickstart
import esbuildServe from 'esbuild-serve';
const buildOptions = {
entryPoints: ['src/index.js'],
outfile: 'dist/bundle.js',
bundle: true,
watch: {
onRebuild(error) {
if (error) console.error('Build failed:', error);
}
}
};
const serveOptions = {
port: 8000,
root: 'public'
};
esbuildServe(buildOptions, serveOptions)
.then(() => console.log('Server started at http://localhost:8000'))
.catch(err => console.error(err));