Error: Cannot Find Module

Oliver Hickman's icon

I'm trying to use some NPM modules. I can run the app from the command line without any issues. When I start the script from Max I get "Error: Cannot Find Module." I've run "script npm install" from Max and did not have any luck. How do I trouble shoot this?

nigel brown's icon

Dear Oliver,
I ran into a similar situation recently. The issue for me was that my patch was only accessing the script and not the rest of the environment that I'd created. Because I am building a standalone application, the solution for me was adding my Node.js project into a Max project and updating the search paths to include the node_modules folder. There's a lot more information about that process in this link: https://docs.cycling74.com/max8/vignettes/03_n4m_projects_devices

Another option is creating your Node.js environment entirely within the Max patch. It boils down to making sure that the patch and access your package.json if you have it and passing script npm install or script npm ci to the node.script object. You can also just pass script npm install with your package arguments if you want to start from scratch without a package.json file. A lot more information about that is in this link: https://docs.cycling74.com/max8/vignettes/02_n4m_usingnpm

I highly recommend checking out those links. They were enormously helpful to me.