e2ebridge/bpmn

"Cannot find module " -- javascript file not found

ieugen opened this issue · 5 comments

The engine cannot find the Javascript file:

My process looks like this:

var bpmn = require("bpmn");
console.log("Start process")
bpmn.createUnmanagedProcess("bpmn/simpleRegistration.bpmn", function(err, myProcess) {
    // we start the process
    myProcess.triggerEvent("Start_registration");
});
$ ls -la bpmn
total 24
drwxr-xr-x 1 ieugen ieugen  184 aug 10 20:40 .
drwxr-xr-x 1 ieugen ieugen  186 aug 10 20:41 ..
-rw-r--r-- 1 ieugen ieugen 6511 aug 10 20:21 simpleRegistration.bpmn
-rw-r--r-- 1 ieugen ieugen  757 aug 10 20:22 simpleRegistration.js
$ node -v 
v2.2.1
$ npm -v
2.11.0
module.js:334
    throw err;
    ^
Error: Cannot find module 'bpmn/simpleRegistration.js'
    at Function.Module._resolveFilename (module.js:332:15)
    at Function.Module._load (module.js:282:25)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Object.exports.getHandlerFromFile (/home/ieugen/contracte/gpec-event/gpec-event/node_modules/bpmn/lib/handler.js:72:12)
    at exports.createUnmanagedProcess (/home/ieugen/contracte/gpec-event/gpec-event/node_modules/bpmn/lib/public.js:36:28)
    at Object.<anonymous> (/home/ieugen/contracte/gpec-event/gpec-event/bpmn-sample.js:5:6)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)

Hello ieugen,

I checked and it is because we use the require function to get the javascript file. So node try to find it from where we call the function not from the root file. You can use the full path to solve this.

var bpmn = require("bpmn");
console.log("Start process")
bpmn.createUnmanagedProcess(__dirname + "/bpmn/simpleRegistration.bpmn", function(err, myProcess) {
    // we start the process
    myProcess.triggerEvent("Start_registration");
});

I've tried it and I get this:

 node bpmn-sample.js 
Start process
/home/ieugen/contracte/gpec-event/gpec-event/bpmn/simpleRegistration.js
[Error: The BPMN file '/home/ieugen/contracte/gpec-event/gpec-event/bpmn/simpleRegistration.bpmn'. contains more than one process definition. Use 'createCollaboratingProcesses' instead of 'createProcess']
/home/ieugen/contracte/gpec-event/gpec-event/bpmn-sample.js:9
    myProcess.triggerEvent("Start_registration");
             ^
TypeError: Cannot read property 'triggerEvent' of undefined
    at /home/ieugen/contracte/gpec-event/gpec-event/bpmn-sample.js:9:14
    at exports.createUnmanagedProcess (/home/ieugen/contracte/gpec-event/gpec-event/node_modules/bpmn/lib/public.js:45:13)
    at Object.<anonymous> (/home/ieugen/contracte/gpec-event/gpec-event/bpmn-sample.js:5:6)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)
    at node.js:946:3

I've made a gist with the files I use [1].

[1] https://gist.github.com/ieugen/a3e66d4ff85db0eb6c9a

Hello,

The issue is that your bpmn process is not executable, there is an attribute "isExecutable" that needs to be set to true. The error message is wrong it actually finds no process definition.

You just have a second error in the trigger you need to use the name of the event with the space "Start registration"

Thank you, got it working. Better error logging/warning might be in order there.

I use bizagi process molder to create a BPMN and on run my node app i get this

Debugger listening on port 8888
%UserPATH%node_modules\bpmn\lib\parsing\errors.js:95
throw error;
^
Error
at throwErrors [as throwError](%UserPATH%node_modulesbpmnlibpa
rsingerrors.js:87:17)