Bug: Can't use require() inside jsextensions folder in a Max Package.

danielj's icon

test-require-package.zip
application/zip 7.50 KB

When trying use require inside a jsextensions folder I get the error:

js calling require without context frame

However, the exact same code will behave as expected when the files are placed outside the Package. I've included a simple package in order to recreate this issue:

1: Quit Max and then place test-require-package inside your packages folder.
2: Navigate to test-require-package > patchers > test and open test.maxpat
3:
When Max launches and the patcher opens, check the max console for the error above.

danielj's icon

test-require-patcher.zip
application/zip 3.56 KB

For comparison here's a version using identical code to the one above, but not including the files in a Package. If you installed the package above in your Packages folder, then launching this patch will trigger the error (this is because the files in jsextensions are global and using a [js] object in any patcher will cause them to be executed).

However, you'll see the message from test-require-patcher is successfully printed below the error messages.

danielj's icon

Bump

Even if this isn't a bug I'd still be interested to know the reason require() doesn't work inside jsextensions. As far as I can see it isn't mentioned as not being supported in the documentation and googling that error message doesn't return anything useful...

danielj's icon

Reached out to support and the solution to this was place the files in a folder named code rather than jsextensions

MIB's icon

Old, post, but I had the same issue and ignored it for a long time since everything seemed to work anyways. Moving the jsextensions into the code folder of the package worked!! Thanks you!

tiago morais morgado's icon

the first question you have to ask yourself is if js extensions are nodejs based. i mean, require was supposed to be there only for node, right?