Skip to content

[Bug]: TinyMCE + Vite 8 (Rolldown) - Module Execution Order Bug #8812

@doberkofler

Description

@doberkofler

Reproduction link or steps

TinyMCE + Vite 8 (Rolldown) - Module Execution Order Bug

vite-rolldown-problem-2.zip

Issue Description

When multiple files independently import tinymce/tinymce, Rolldown incorrectly orders module execution in production builds. Side-effect imports (tinymce/models/dom) execute before the main tinymce module is initialized, causing ReferenceError: tinymce is not defined.

Reproduction Steps

  1. Install dependencies:

    npm install
  2. Run development mode (WORKS):

    npm run dev
    • Open browser → No errors
    • TinyMCE initializes correctly
  3. Build for production (FAILS):

    npm run preview
    • Open browser console
    • ERROR: Uncaught ReferenceError: tinymce is not defined
    • Error occurs in bundled models/dom module

Root Cause

The bug is triggered by Shared Chunk Extraction in Rolldown:

  1. Multiple entry points (10 modules) import the same wrapper.
  2. Rolldown extracts TinyMCE into a shared chunk (e.g., assets/utils-[hash].js).
  3. Inside this shared chunk, the module order is corrupted:
    • models/dom is wrapped as an IIFE and executed immediately: })))();
    • tinymce/tinymce is wrapped as a lazy CJS module and not yet executed.
    • Immediate execution fails because tinymce global is missing.

Verification of Bug (Manual)

If for some reason the browser console doesn't show the error immediately, you can verify the bug by inspecting the generated code:

  1. Look in dist/assets/ for the large shared chunk (e.g., utils-v9yuU6bo.js).
  2. Search for the string })))();.
  3. You will find it at the end of the models/dom module region.
  4. Note that the main tinymce module nearby ends with })); (lazy) while models/dom ends with })))(); (immediate). This is the bug.

Workaround

Add to vite.config.ts:

export default {
	build: {
		rollupOptions: {
			output: {
				strictExecutionOrder: true, // Forces correct module order
			},
		},
	},
};

What is expected?

To work like vite 7

What is actually happening?

It fails

System Info

System:
    OS: macOS 15.7.4
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 1022.98 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.14.0 - /Users/doberkofler/.nvm/versions/node/v24.14.0/bin/node
    npm: 11.11.1 - /Users/doberkofler/.nvm/versions/node/v24.14.0/bin/npm
    pnpm: 10.32.1 - /usr/local/bin/pnpm
    bun: 1.2.19 - /Users/doberkofler/.bun/bin/bun
    Watchman: 2026.03.09.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 146.0.7680.153
    Safari: 26.3.1

Any additional comments?

No response

Metadata

Metadata

Labels

No labels
No labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions