parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Error on adding code to parse server example project

Open candork opened this issue 10 years ago • 3 comments

I have followed instruction here http://blog.parse.com/learn/parse-server-video-series-april-2016/

And installed the parse sever locally, I ran the parse server and it worked fine.

Next, I added my cloud code directory, it replaced my main.js file. Now when I run the server (npm start) it I get this error

npm start

> [email protected] start /Users/r/parse-backend
> node index.js

module.js:341
    throw err;
    ^

Error: Cannot find module '/cloud/playCountUpdate.js'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/r/parse-backend/cloud/main.js:6:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/5.11.0/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.11.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the parse-server-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs parse-server-example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls parse-server-example
npm ERR! There is likely additional logging output above.

Here is how my cloud code file looks

require('/cloud/playCountUpdate.js');
Parse.Cloud.define('hello_2', function(req, res) {
  res.success('Hi');
});

candork avatar Apr 28 '16 01:04 candork

Have you tried require('playCountUpdate') or other variations? There are several videos in the page you linked, can you specify which steps you followed?

hramos avatar Apr 28 '16 05:04 hramos

Thanks for all your work @hramos! I have learned a lot from all your answers/articles/docs 👍

So, I tried them all and finally found that this works:

require('../cloud/activityJob.js');

I think you should update the document - https://github.com/ParsePlatform/parse-server/wiki/Migrating-an-Existing-Parse-App#3-cloud-code

The video I was referring to was, this - https://www.youtube.com/watch?v=o522ovITvW4

Thanks again! :)

candork avatar Apr 28 '16 05:04 candork

@candork is activityJob.js a separate file? How did this help npm to locate your playCountUpdate.js module?

I'm having a similar problem and I'm wondering if there's a separate file I need to create and/or require in my main.js or index.js file.

jessicahzuber avatar Oct 04 '17 16:10 jessicahzuber