rollup-plugin-tla

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

A Rollup plugin that enables top-level await (TLA) support for IIFE and UMD output formats, which Rollup does not natively support. Version 0.0.2 adds TypeScript declarations and supports Node.js >=14.18. It works by transforming the output to use a dynamic import or wrapper to handle TLA. Differentiators: lightweight, no additional runtime dependencies, and specifically targets IIFE/UMD where Rollup's own TLA handling is absent.

error Error: [object Object] is not a Rollup plugin
cause Using a named import instead of default import leads to the plugin object being malformed.
fix
Change import { tla } from 'rollup-plugin-tla' to import tla from 'rollup-plugin-tla'.
error ${tla} is not a function
cause Trying to use require() in an ESM-only context – require returns the module object, not the plugin function.
fix
Use import instead of require.
error Top-level await is not supported in the configured output format
cause Output format is not IIFE or UMD; Rollup fails natively.
fix
Set output.format to 'iife' or 'umd'.
gotcha Plugin only works for IIFE and UMD formats; for ESM or CJS, Rollup natively supports TLA and this plugin is unnecessary.
fix Ensure output format is 'iife' or 'umd'.
gotcha The plugin transforms the output to use a dynamic import or wrapper; this may cause side effects if not used carefully with other plugins that manipulate the AST.
fix Test the bundle thoroughly with your specific plugin chain.
deprecated Package has not been updated since early 2023; compatibility with newer Rollup versions (>=3) is not guaranteed.
fix Consider alternative approaches or test with Rollup v3+.
npm install rollup-plugin-tla
yarn add rollup-plugin-tla
pnpm add rollup-plugin-tla

Shows how to add top-level await support for IIFE output format using rollup-plugin-tla.

import tla from 'rollup-plugin-tla';

export default {
  input: 'src/index.js',
  output: {
    format: 'iife',
    file: 'dist/bundle.js'
  },
  plugins: [
    tla()
  ]
};