Max for Live device - javascript require() doesn't work without editor open

Jason Priebe's icon

This is probably a really stupid question, but I've searched the web and these forums for an hour or two looking for an answer. I hope somebody here has experience packaging max for live devices with multiple javascript files.

I am working on a Generative MIDI Tool in Max for Live (Live 12). The main patcher has a js object that references a javascript file. That file uses require() to load in another file. All told, there are 13 javascript files that get required by each other to generate the midi notes.

Everything works great when I have the Max for Live editor open. I can push the "apply" button in Live, and the code generates notes as expected.

But when I freeze the device and save it, I push the "apply" button, and I get the error message "Did not receive a note dictionary in time". I can't see anything in the Max for Live console (unfortunately, nothing shows up in there unless the device is open in the patcher editor). But I do suspect that this is an issue with require(). Sometimes I do see an error in the console like "foo is not a function" ("foo" being the function I am referencing from the required file).

A couple of notes:

  • all my JS files are in /Users/MYUSERNAME/Documents/Max 8/Max for Live Devices/MYDEVICENAME/code

  • The main.js file is referenced in my js object

  • All my other JS files are included in the project -- I clicked "Show containing project", and I added all the other JS files to the project

  • Sometimes I get an error "multiple identical files named foo.js were found in the project folder. Merged to code". Not sure what to make of that.

  • my require calls look like this:

    var { generate } = require('./code/generator.js')



    generator.js has this definition:

    exports.generate = function () {
    ...


    }

    then I try to call the function as generate(). This syntax is new to me; I'm more used to getting an object back from require() and calling the function on that object. But this works just fine when the Max for Live editor is open, so I think it's valid.

I'm using Live 12.0.1 on MacOS Sonoma 14.3 (apple silicon) with Max 8.6.0, if any of that matters.

Thanks for any help!

Jason Priebe's icon

Following up on my own post:

  • I tried upgrading to Max 8.6.2

  • I tried removing the ".js" from all my require() calls

  • I found a MacVim session that had one of my JS files open. I shut that down

I froze and saved, and now things are working. I have no idea which of these things made it work.