node.script with relative path (windows + mac)
Hello,
We are making progress with our NestJS integration.
But we now have a rather trivial problem that Max behaves differently under Windows than a Mac in terms of relative paths.
Under Windows the following works:
node.script ./../dist/main.js @autostart 1 @watch 1
The Mac, on the other hand, reports in the console:
./../dist/main.js: No such file or directory
Does anyone have a tip to solve this - apart from copying the Max patch into the dist folder?
Regards and thx
Ralf
We solved this with a simple workaround. A lauchner.js in the directory of the max patch:
try {
require('./../dist/main')
} catch (error) {
console.error('main.js not found - please run: "npm run build" first')
}
Hi Ralf.
while it might not be obvious on first sight if you are used to a NodeJS style of thinking wrt imports and paths, [node.script]
uses the Max search path to determine the path of your entry point.
The search path is a flat namespace, so instead of using a relative path as the argument I'd recommend using a more unique, potentially namespaced filename (eg. fde.nestlauncher.js
).
If you do have needs on the Node side to do dynamic imports based on the platform / runtime you could your examplelauncher.js
is probably the most straightforward way to handle that.