{"id":25424,"library":"esbuild-plugin-wat","title":"esbuild-plugin-wat","description":"esbuild plugin (v0.2.7) for importing WebAssembly (.wasm) and WebAssembly text format (.wat) files. Resolves imports to a default Uint8Array export suitable for WebAssembly.instantiate()/compile(). Ships TypeScript types. Differentiators: supports .wat compilation via wabt.js with caching, optional binaryen inlining optimization, configurable loader (binary/base64/file), experimental bundling of multiple wat/wasm files using import syntax. Lightweight alternative to full-featured bundler plugins like wasm-pack.","status":"active","version":"0.2.7","language":"javascript","source_language":"en","source_url":"https://github.com/mitschabaude/esbuild-plugin-wat","tags":["javascript","wasm","wat","esbuild","typescript"],"install":[{"cmd":"npm install esbuild-plugin-wat","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-wat","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-wat","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - plugin requires esbuild to function","package":"esbuild","optional":false},{"reason":"converts .wat to .wasm; bundled as dependency","package":"wabt","optional":true},{"reason":"optional optimization for function inlining","package":"binaryen","optional":true}],"imports":[{"note":"Package is ESM-only; default export is a function, not an object.","wrong":"const watPlugin = require('esbuild-plugin-wat')","symbol":"default","correct":"import watPlugin from 'esbuild-plugin-wat'"},{"note":"Type import only; WatPlugin is an interface, not a runtime value.","wrong":"import { WatPlugin } from 'esbuild-plugin-wat'","symbol":"WatPlugin","correct":"import type { WatPlugin } from 'esbuild-plugin-wat'"},{"note":"Type import for configuration object shape.","wrong":"import { PluginOptions } from 'esbuild-plugin-wat'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'esbuild-plugin-wat'"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport watPlugin from 'esbuild-plugin-wat';\n\nawait build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/out.js',\n  plugins: [watPlugin({\n    loader: 'binary', // default: inline .wasm as binary\n    // loader: 'file',  // emit separate .wasm files\n    inlineFunctions: false,\n    wasmFeatures: { simd: true },\n    // bundle: true, // experimental bundling of wat modules\n  })],\n});\n\n// In your source:\n// import wasm from './example.wat';\n// const module = await WebAssembly.instantiate(wasm);","lang":"typescript","description":"Demonstrates esbuild configuration with watPlugin to import .wat files as Uint8Array, showing default options and commented alternatives."},"warnings":[{"fix":"Use: const { instance } = await WebAssembly.instantiate(wasm);","message":"Default export is a Uint8Array, not a compiled WebAssembly.Module. Must call WebAssembly.instantiate()/compile() explicitly.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use 'binary' (default) to inline the binary; use 'file' only if you control the static file serving and path resolution.","message":"Setting loader to 'file' may cause runtime fetch errors if the .wasm file path is not correctly resolved in production builds.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Switch to ESM imports: import watPlugin from 'esbuild-plugin-wat'","message":"v0.2.0 dropped support for CommonJS require. package.json type field changed to 'module'.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Create a fresh options object per build call: watPlugin({ ... })","message":"Options object is mutable and shared across builds; avoid reusing same config object for multiple esbuild runs.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Test thoroughly with your .wat files; fall back to multiple separate .wasm imports if issues arise.","message":"Bundling (bundle: true) is experimental and does not support all wasm import syntaxes.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import statement or set { \"type\": \"module\" } in package.json.","cause":"Package is ESM-only; require() fails in CJS context.","error":"Cannot find module 'esbuild-plugin-wat'"},{"fix":"Use watPlugin() (a function call) in plugins array, not just watPlugin reference.","cause":"Calling watPlugin incorrectly, e.g., watPlugin without parentheses.","error":"Error: esbuild plugin 'wat' must be a function or an object with a name property"},{"fix":"Ensure the default export is used as-is: const wasm = await import('./file.wat'); WebAssembly.instantiate(wasm.default);","cause":"Passing a string (e.g., base64) instead of Uint8Array to instantiate.","error":"TypeError: WebAssembly.instantiate: first argument must be a BufferSource or WebAssembly.Module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}