Debugging in Node4Max

maybites's icon

Hi

I am unable to debug Node4Max scripts inside Visual Studio Code.

I followed all the instructions in the Reference and the linked Websites.

when I set the object to

[node.script mqtt.js @watch 1 @options --inspect-brk]

and the debugger launch.json "program" property points to the mqtt.js script

and start the debugger inside VSC I, VSC throws a

Cannot find module 'max-api'

what to do, now?

cheers

martin

geofholbrook's icon

I did this successfully using the "Attach to Node Process" command in VS Code. Did you try that?

The problem with "launching" is that your js file isn't runnable outside of the max environment. You'd get the same error if you tried to run it from the terminal, like `node mqtt.js` ... because max-api isn't in the node_modules folder. It must be "under the hood" somehow when you run it from a max patch (someone else might be able to shed more light on that).

maybites's icon

@geofholbrook
thank you for the link. In the meantime I switched the development environment to webstorm and I had to figure it out for myself. but thanks to your hints I was successful.

for future reference (and nodejs noobs):

debugging [node.script] requires an 'attach' debugging.

In case of webstorm:

1. start [node.script] with @option --inspect-brk=9229
2. open webstorm menu -> Run -> Edit configurations .. -> + -> Add new config.. -> Attach to node.js/chrome
3. make sure your File /Directory points to the root of your nodejs script
4. start debugging by menu -> Run -> Debugg ... -> select the new configuration

off you go..

reference: https://www.jetbrains.com/help/webstorm/running-and-debugging-node-js.html#ws_node_debug_remote_chrome