esbuild-gas-plugin

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

esbuild plugin for Google Apps Script that bundles TypeScript/JavaScript into a single file compatible with the GAS runtime. Current version 0.10.0, actively maintained with frequent releases. Key differentiators: supports both Rhino and V8 runtimes, works with Node.js and Deno, generates JSDoc annotations for better GAS autocompletion, and is inspired by gas-webpack-plugin but leverages esbuild's faster build times.

error ERROR: Cannot find module 'esbuild-gas-plugin'
cause Package not installed or missing from node_modules.
fix
Run npm install -D esbuild-gas-plugin or your package manager's equivalent.
error TypeError: GasPlugin is not a function
cause Using GasPlugin incorrectly (e.g., calling it as a function instead of passing as an object). GasPlugin is a plugin object, not a factory.
fix
Use plugins: [GasPlugin] (without invoking).
error Error: Build failed with 1 error: error: No matching entry point for format 'esm'
cause Entry point pattern is not an array or not a string.
fix
Ensure entryPoints is an array of strings: entryPoints: ['src/index.ts'].
error ReferenceError: globalThis is not defined
cause Using the plugin with an older Node.js version (<12) that does not support globalThis.
fix
Upgrade Node.js to version 12 or later.
breaking In v0.9.0, support for the Rhino engine was added. Existing builds targeting V8 may need to check compatibility if they use Rhino-specific features.
fix Ensure your GAS project uses V8 runtime or test accordingly.
deprecated The plugin previously used a 'use export' pattern in v0.4.0 but now defaults to JSDoc generation. Scripts relying on the old export style may break.
fix Upgrade to 0.10.0 and verify output format.
gotcha Entry points must be an array of strings, but only the first element is used. Providing multiple entries will not bundle them together as expected.
fix Use a single entry point file that imports other modules.
gotcha When using the plugin with Deno, you must import from 'npm:esbuild-gas-plugin@0.7.0' (or later). Older versions may not work with Deno.
fix Use at least version 0.7.0 for Deno compatibility.
npm install esbuild-gas-plugin
yarn add esbuild-gas-plugin
pnpm add esbuild-gas-plugin

Minimal setup to bundle a TypeScript entry point for Google Apps Script with esbuild and the gas plugin.

// build.mjs
import { build } from 'esbuild';
import { GasPlugin } from 'esbuild-gas-plugin';

await build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'dist/bundle.js',
  plugins: [GasPlugin],
});
console.log('Build complete');

// Run with: node build.mjs