You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Places that indicate that absolute path is necessary:
#1183: You shoud use absolute path for your cloud code.
README.md: cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code
The issue is that using ./cloud/main.js as the cloud code path actually loads [root]/node_modules/parse-server/lib/cloud/main.js, instead of the expected [root]/cloud/main.js, and it does so silently (since the require() call is successful). Once the wrong main.js file is loaded, any call to cloud code results in Error: Invalid function. (which is hard to debug).
It would be great if using ./cloud/main.js worked as expected. In my case, I'm loading my parse config from config files, so I cannot (easily) do __dirname + '/cloud/main.js'. It also seems cleaner to be able to reference the file relatively (and it makes the code that much more portable).
In some informal testing, it appears that modifying ParseServer.js to do a simple path.resolve(cloud) in the require() at line 212 allows my main.js file to be loaded correctly. I'm not familiar enough with Parse Server (or even Node.js) to suggest that as a competent solution without someone else's sanity check, but I ran the tests and they all passed (although there doesn't appear to be much testing around loading cloud code files). If someone can gut-check this solution (or propose a better one) I'd be happy to submit a PR.
If the consensus is instead that using a relative path is off the table, I can provide a PR to fix the comment, but someone else will have to fix the wiki example.
The text was updated successfully, but these errors were encountered:
Steps to reproduce
I've seen conflicting information regarding whether or not using a relative path to the cloud code is allowed:
The info that states it is supported:
// "cloud": relative location to cloud code to require
cloud: './cloud/main.js',
Places that indicate that absolute path is necessary:
You shoud use absolute path for your cloud code.
cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code
The issue is that using
./cloud/main.js
as the cloud code path actually loads[root]/node_modules/parse-server/lib/cloud/main.js
, instead of the expected[root]/cloud/main.js
, and it does so silently (since therequire()
call is successful). Once the wrongmain.js
file is loaded, any call to cloud code results inError: Invalid function.
(which is hard to debug).It would be great if using
./cloud/main.js
worked as expected. In my case, I'm loading my parse config from config files, so I cannot (easily) do__dirname + '/cloud/main.js'
. It also seems cleaner to be able to reference the file relatively (and it makes the code that much more portable).In some informal testing, it appears that modifying
ParseServer.js
to do a simplepath.resolve(cloud)
in therequire()
at line 212 allows mymain.js
file to be loaded correctly. I'm not familiar enough with Parse Server (or even Node.js) to suggest that as a competent solution without someone else's sanity check, but I ran the tests and they all passed (although there doesn't appear to be much testing around loading cloud code files). If someone can gut-check this solution (or propose a better one) I'd be happy to submit a PR.If the consensus is instead that using a relative path is off the table, I can provide a PR to fix the comment, but someone else will have to fix the wiki example.
The text was updated successfully, but these errors were encountered: