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

danielj's icon

danielj

Nov 18, 2019, 1:13 AM

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

danielj

Nov 18, 2019, 1:25 AM

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

danielj

Nov 21, 2019, 12:50 AM

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

danielj

Dec 10, 2019, 11:37 PM

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

MIB's icon

MIB

Oct 10, 2024, 7:45 AM

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

tiago morais morgado

Oct 25, 2024, 8:52 PM

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?