Rollup Monaco Bundler
rollup-monaco-bundler is a specialized Rollup utility designed to bundle `monaco-editor` dependencies, particularly focusing on generating UMD-formatted output. Its core differentiator is the provision for dynamic runtime National Language Support (NLS) injection, enabling `monaco-editor` to load language packs at runtime rather than bundling all of them upfront. The package, currently at version 1.0.2, appears to be in maintenance mode with its last notable activity around March 2025. Unlike other Monaco-specific Rollup plugins which might focus solely on bundling, this package explicitly targets the externalization of Monaco dependencies and efficient NLS handling for optimized bundle sizes in web applications. It's best suited for projects that require `monaco-editor` in a UMD context and need fine-grained control over internationalization.
Common errors
-
Error: "[name] is not exported by [module]"
cause A module, likely a CommonJS dependency of Monaco, is being imported as an ES Module, but Rollup cannot determine the correct export. Often occurs when `@rollup/plugin-commonjs` is missing or incorrectly placed.fixEnsure `@rollup/plugin-commonjs` is installed and included in your `rollup.config.ts` plugins array, placed *after* `@rollup/plugin-node-resolve` and *before* `@rollup/plugin-typescript` if both are present. You might need to add specific `namedExports` configurations to `@rollup/plugin-commonjs` for problematic modules. -
Monaco editor worker files are not found or fail to load.
cause Monaco editor relies on web workers for language services. If the worker scripts are not correctly bundled, served from the correct path, or if their URLs are misconfigured, they will fail to load, preventing the editor from fully functioning.fixEnsure your Rollup configuration correctly handles copying or bundling worker scripts to the output directory and that the Monaco editor's global configuration (`monaco.config`) points to the correct `vs` path where these workers are located. This might involve using `rollup-plugin-copy` or similar. -
TypeError: Cannot read properties of undefined (reading 'config') or similar when loading Monaco.
cause This often happens if the global `monaco` object is not correctly initialized or if `monaco-editor` is being loaded multiple times or in an incompatible way (e.g., mixing CDN-loaded Monaco with a bundled version).fixEnsure `monaco-editor` is loaded consistently, either entirely via a bundler (using `rollup-monaco-bundler` and other plugins) or entirely via a CDN. Avoid duplicate or conflicting `monaco.config` calls. Verify that the Monaco loader configuration, if used, is applied correctly before editor initialization.
Warnings
- breaking `monaco-editor` itself has transitioned heavily towards ESM builds, deprecating its AMD build. While `rollup-monaco-bundler` aims for UMD, direct integration with the latest `monaco-editor` versions (0.50.0+ as of early 2026) might require careful configuration or may not be fully compatible with older patterns used by this bundler, potentially leading to build failures or unexpected runtime behavior.
- gotcha To effectively bundle `monaco-editor` and its dependencies, `rollup-monaco-bundler` must be used alongside other essential Rollup plugins such as `@rollup/plugin-typescript` (for `rollup.config.ts` and source files), `@rollup/plugin-node-resolve` for resolving `node_modules` paths, and `@rollup/plugin-commonjs` for handling CommonJS modules. Failing to include or correctly configure these plugins will likely result in build errors.
- gotcha The `monaco-editor` can produce very large bundles, impacting load times. This bundler aims to help with NLS, but overall bundle size requires careful configuration of Monaco features, languages, and potentially aggressive tree-shaking or dynamic imports.
- gotcha Rollup configuration files (e.g., `rollup.config.js` or `rollup.config.ts`) themselves are typically treated as ES Modules by modern Rollup versions. Mixing CommonJS (`require`) syntax in a TypeScript configuration or expecting global variables like `__dirname` to work without special handling can lead to errors.
Install
-
npm install rollup-monaco-bundler -
yarn add rollup-monaco-bundler -
pnpm add rollup-monaco-bundler
Imports
- RollupMonacoBundler
const RollupMonacoBundler = require('rollup-monaco-bundler');import { RollupMonacoBundler } from 'rollup-monaco-bundler'; - monacoNlsInject
import monacoNlsInject from 'rollup-monaco-bundler/nls';
import { monacoNlsInject } from 'rollup-monaco-bundler'; - Rollup options
import type { RollupOptions } from 'rollup';
Quickstart
import { defineConfig } from 'rollup';
import { monacoNlsInject } from 'rollup-monaco-bundler';
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig({
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'umd',
name: 'MonacoEditorBundle',
sourcemap: true,
},
plugins: [
nodeResolve(),
commonjs(),
typescript(),
monacoNlsInject({
locale: process.env.MONACO_LOCALE || 'en',
// Other options like 'basePath', 'ignore' can be configured here.
// Refer to the plugin documentation for full options.
}),
// Other Rollup plugins for CSS, assets, etc. may be needed
],
external: [
// List any modules that should not be bundled here, e.g., 'monaco-editor'
// if you intend to load it separately or from a CDN.
]
});