3

enter image description hereI am trying to deploy a create-react-app https://github.com/lrtico/allowance-tracker I developed to Google Cloud and am getting this error in Error Reporting when visiting the web page https://allowance-tracker-287504.wn.r.appspot.com/:

Error: Cannot find module '/workspace/server.js'
  at Function.Module._resolveFilename (loader.js:636)
  at Function.Module._load (loader.js:562)
  at Function.Module.runMain (loader.js:831)
  at startup (internal/bootstrap/node.js:283)
  at bootstrapNodeJSCore (internal/bootstrap/node.js:623)

As a test, I deployed the same build to Azure and the app runs perfectly. Any ideas on what I am missing?

  • you haven't handlers defined in the app.yaml. Is it normal? – guillaume blaquiere Aug 27 '20 at 09:15
  • Not sure whether [this thread](https://stackoverflow.com/questions/61740611/could-not-find-module-workspace-server-js) will help you or not. Feel free to refer it. – Digil Aug 27 '20 at 14:07
  • Thank you @guillaumeblaquiere! I don't know if it's normal...I'm a frontend developer tinkering around in backend stuff - lol. I'll try to understand handlers to see if that's the issue. – Jackson Powell Aug 27 '20 at 20:31
  • Thank you @Digil! I did read that thread and it seemed to me my problem is with Google Cloud not the source code since I can deploy it on Azure (with the same app.yaml and package.json file and source code). – Jackson Powell Aug 27 '20 at 20:34
  • Does it only a front end web site? What is the first page called? – guillaume blaquiere Aug 27 '20 at 20:51
  • @guillaumeblaquiere I really appreciate your trying to help me figure this out! I think you are asking if the web app has a database or not, and the answer is no it doesn't. For this first iteration, I'm using local storage to save the data entered and created by the app. I'll edit the OP with a screenshot of the presentation layer. – Jackson Powell Aug 28 '20 at 23:35

3 Answers3

4

I was right. I tested and I successfully deployed on App Engine by updating the app.yaml

  1. Start by doing a npm run build
  2. Then update the app.yaml file like this
runtime: nodejs10

handlers:
  - url: /
    static_files: build/index.html
    upload: build/index.html

  - url: /
    static_dir: build
  1. deploy your app gcloud app deploy
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
3

I experienced the same error. It was because I mistakenly removed the start script.

From the GCP AppEngine doc :

By default, the runtime starts your application by running node server.js. If you specify a start script in your package.json file, the runtime runs the specified start script instead

The other way is as defined here :

You can override this behavior by specifying a script in the entrypoint field in app.yaml. Instead of running node server.js or a start script, the runtime starts your application with the command you specify in entrypoint

See : https://cloud.google.com/appengine/docs/standard/nodejs/runtime#application_startup

John Doe
  • 1,092
  • 3
  • 12
  • 25
1

Make sure your package.json has start command.

"scripts": {
  "start": "node app.js"
}
Dipen Bhikadya
  • 3,318
  • 3
  • 21
  • 19