简体   繁体   中英

Error: Cannot find module '/workspace/server.js' upon node js deploy on google app engine

After a week of searching, I am not able to find a solution for an app engine deploy issue for my node.js application.

I have come to the point that I have replaced my original code with this "hello world" example for express . Running this in my local dev environment offline works well (as expected).

Then I deploy this app to my google app engine project online using the gcloud cli. That seems to work as well (no errors).

However, when I visit the app online, instead of seeing my app, I see a black page with this message: "Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds.". After some digging in the google cloud console logs, I find that the error seems to be "Error: Cannot find module '/workspace/server.js'" (see more info here ). I do not use such a module myself, nor do I define such a path in any of my files.

Does anyone have an idea what might be going wrong and how I can fix it? I have deployed apps successfully recently, but I'm at a loss here...

As Cadet pointed out correctly, the solution was to make some changes to my app.yaml file.

This page allowed me to find the needed handlers.

Thanks a lot, Cadet.

In my case, I got carried away with my .gcloudignore file

I used .gcloudignore to ignore directories like bin , but I forgot that bin contained the file www which was the file run by my package.json "scripts">"start"

 {
  "name": "craft",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
  ...

If .gcloudignore ignores a directory, that directory is not deployed to Google App Engine, therefore I got the error:

Cannot find module '/workspace/bin/www'

So the solution was to stop ignoring certain files.

I know this is not the solution for the OP (OP says they needed changes to their app.yaml handlers ) but it may help other people!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM