Javascript task listener with script as a IIFE


I’m using JavaScript in my task/execution listeners and have a question about sharing code between different scripts. I have split my shared functions out into a separate file and am using webpack to generate a single script file per listener to reference in my BPMN.

As a simplified example:

  • ScriptA.js contains some shared code
  • ScriptB.js contains my task listener for TaskB
  • ScriptC.js contains my task listener for TaskC

Webpack is configured to generate two outputs:

  1. ScriptB.js (which actually contains ScriptA + ScriptB)
  2. ScriptC.js (which actually contains ScriptA + ScriptC)

I then reference these output scripts as my task listeners in the BPMN.

Problem: webpack generates the outputs wrapped in an IIFE like so:

(() => { 
     /// script code here
     execution.setVariable('greeting', 'Hello Camunda');

which the Camunda execution engine doesn’t seem to approve of. I consistently get the error “Expected an operand but found <my script’s contents here>”.


  • Are IIFEs not supported by the script execution engine? Am I missing something obvious?
  • Is there a better way for me to reuse code between listener scripts?

Apologies if this has been asked and answered before on the forum or in the documentation - I tried searching through both but haven’t found anything.