Skip to content

fix(examples): fix EventEmitter heritage error in examples#3550

Open
Jo-Byr wants to merge 1 commit into
Kitware:masterfrom
Jo-Byr:fix-event-emitter-error
Open

fix(examples): fix EventEmitter heritage error in examples#3550
Jo-Byr wants to merge 1 commit into
Kitware:masterfrom
Jo-Byr:fix-event-emitter-error

Conversation

@Jo-Byr

@Jo-Byr Jo-Byr commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Context

Some examples (XMLImageDataWriter, XMLPolyDataWriter, SurfaceLICMapper, GeometryViewer, ImageViewer, OctreeViewer, TubesViewer, VolumeViewer, TimeSeries, VolumeMapperLightAndShadow, WebXRChestCTBlendedCVR, WebXRHeadFullVolumeCVR, WebXRHeadGradientCVR and WebXRVolume) fail due to a class heritage events_1.EventEmitter is not an object or null error.

Results

This PR fixes this issue in these examples, though other errors remain in some of the examples cited.

Changes

Added "vite-plugin-node-polyfills" dependency

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat to have correctly formatted code

@Jo-Byr
Jo-Byr requested a review from finetjul July 15, 2026 12:13
@Jo-Byr Jo-Byr self-assigned this Jul 15, 2026

@finetjul finetjul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been great to have more information about the problem in the commit message.

@Jo-Byr

Jo-Byr commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

It would have been great to have more information about the problem in the commit message.

I'm not sure to 100% understand the issue but from what I could get, Vite does not resolve correctly events and treat them as undefined and "vite-plugin-node-polyfills" fixes this.

@finetjul

Copy link
Copy Markdown
Member

Do you know what's specific about those examples ? Why are they different from the other working examples ?

@daker

daker commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

@finetjul all those examples end up using xmlbuilder2, the newer version of xmlbuilder has introduced the usage of node EventEmitter for callback https://github.com/oozcitak/xmlbuilder2/blob/10b65492d4c47a3a7c88e430be5b1d7bbd0ac85a/src/builder/XMLBuilderCBImpl.ts#L22

@Jo-Byr We have already fixed the tests using the official @rolldown/plugin-node-polyfills maybe we should use it instead of adding a new deps 3aff1e3#diff-bf00a51cbcbfbf0db010355fe55fe1d8417c1f188068e9d688e077820a398cb3R45-R47

@Jo-Byr

Jo-Byr commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@daker I'm not sure to understand the fix you suggest. I tried moving @rolldown/plugin-node-polyfills to dependencies instead of devDependencies but it does not fix the problem.

@finetjul

Copy link
Copy Markdown
Member

@daker I'm not sure to understand the fix you suggest. I tried moving @rolldown/plugin-node-polyfills to dependencies instead of devDependencies but it does not fix the problem.

@Jo-Byr this has to do with how the examples are built, you need to enable the plugin. Please look at build-examples.mjs

@Jo-Byr

Jo-Byr commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@Jo-Byr this has to do with how the examples are built, you need to enable the plugin. Please look at build-examples.mjs

If I'm not mistaken, this would only cover built examples, not examples ran with npm run example.

I added nodePolyfills() and optimizeDeps: { rolldownOptions: { plugins: [nodePolyfills()],},}, to createExampleConfig in vite.example.config.js and it works.

But adding nodePolyFills() to createExamplePlugins and optimizeDeps: { rolldownOptions: { plugins: [nodePolyfills()],},} in createSharedViteConfig in buil-examples.mjs does not fix the problem in built examples

@daker

daker commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

@Jo-Byr here is the patch, no need for a new deps

diff --git a/Utilities/ExampleRunner/vite.example.config.mjs b/Utilities/ExampleRunner/vite.example.config.mjs
index 169b9a37e2..5c16f9b331 100644
--- a/Utilities/ExampleRunner/vite.example.config.mjs
+++ b/Utilities/ExampleRunner/vite.example.config.mjs
@@ -1,10 +1,10 @@
 import path from 'path';
+import nodePolyfills from '@rolldown/plugin-node-polyfills';
 import {
   glslPlugin,
   svgRawPlugin,
   cjsonPlugin,
   workerInlinePlugin,
-  ignorePlugin,
   serveStaticDataPlugin,
 } from '../build/plugins.mjs';
 
@@ -44,6 +44,11 @@ export function createExampleConfig({
       __BASE_PATH__: JSON.stringify(''),
       global: 'globalThis',
     },
+    optimizeDeps: {
+      rolldownOptions: {
+        plugins: [nodePolyfills()],
+      },
+    },
     css: {
       modules: {
         localsConvention: 'camelCaseOnly',
@@ -63,7 +68,6 @@ export function createExampleConfig({
       glslPlugin(),
       svgRawPlugin(),
       cjsonPlugin(),
-      ignorePlugin(['crypto']),
       serveStaticDataPlugin(repoRoot),
       {
         name: 'vtk-example-runner-entry',

@Jo-Byr
Jo-Byr force-pushed the fix-event-emitter-error branch from 0429cda to 43318e6 Compare July 20, 2026 06:44
@Jo-Byr

Jo-Byr commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@Jo-Byr here is the patch, no need for a new deps

Thank you, it's corrected.

@daker daker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants