#15464·bokeh

Use indirect eval for CustomJS imports

Author: bryevdvCreated Sep 25, 2026Updated Sep 25, 2026
Labelstag: component: bokehjs

Applications that bundle BokehJS with esbuild report warnings like this:

[WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]

    ../../../build/js/lib/models/callbacks/customjs.js:44:29:
      44 │         const module = await eval(`import("${url}")`);
         ╵                              ~~~~

  You can read more about direct eval and bundling here: https://esbuild.github.io/link/direct-eval

The warning points to CustomJS._compile_module(). BokehJS uses eval() there to keep a runtime import() of a Blob URL from being transformed into require() when producing the classic bundle.

The evaluated expression does not need access to local lexical bindings, so direct eval is unnecessary. The warning is nevertheless emitted whenever a downstream bundler processes the module, even when the application does not create an ES-module CustomJS callback.

Suppressing direct-eval in BokehJS's own build does not help downstream consumers. Angular's application builder also does not expose esbuild's logOverride setting for applications to suppress this diagnostic.

Proposed solution

Use indirect eval for the runtime import:

typescript
const module = await globalThis.eval(`import("${url}")`)

This preserves the native runtime import needed by the classic bundle while preventing esbuild and other bundlers from treating the call as direct eval.

The change should also:

  • remove BokehJS's internal direct-eval suppression;
  • preserve traditional function-body CustomJS behavior;
  • preserve ES-module callbacks and their args, object, and data arguments;
  • verify that downstream Angular/esbuild, Vite, Webpack, and Rspack builds no longer report direct-eval.

CSP implications

This does not relax or otherwise change BokehJS's CSP requirements.

Both direct and indirect eval require permission for dynamic JavaScript evaluation. Traditional CustomJS function bodies use new Function(), while module-mode callbacks additionally import JavaScript from a Blob URL. Applications using restrictive CSP policies must continue to allow the corresponding evaluation and Blob-script sources.