cannot find module /srv/server.js - gcloud app eng

2020-08-26 03:08发布

问题:

The error I get when trying to deploy my service to app engine is:

Error: Cannot find module '/srv/server.js' at 

`Function.Module._resolveFilename (module.js:548:15) at 

Function.Module._load (module.js:475:25) at Function.Module.runMain 

(module.js:694:10) at startup (bootstrap_node.js:204:16) at 

bootstrap_node.js:625:3`

I dont have a /srv/server.js and why would it look for it?!?!?

Thanks if you can help!

回答1:

Check your package.json, you should have at least:

"main": "app.js"

where app.js is your node-file which starts the server.

You could also add:

"scripts": {
    "start": "node app.js"
},

and run "yarn start" to test that your server starts ok.



回答2:

I solved the problem by putting the App Engine deployment file in the project home:

Home path nodejs project



回答3:

Better late than never.

The error is coming up because you are loading the relative path.

Solution:

"scripts": {
    "start": "node ./app.js"
},