mozyのかきおき

mozyの読書感想文や思考置き場

【解決】GCP で Error: Cannot find module '/srv/server.js' が出た時

タイトルの通り

GCPのApp EngineでNode.jsを使っている際に、以下のようなエラーに遭遇した。 地味なエラーだがピンポイントで解決している記事がなかったため記載。
When using Node.js on GCP's App Engine, I encountered this error. I'll write it because I can't find a good solution.

Error: Cannot find module '/srv/server.js'
Function.Module._resolveFilename (module.js)

解決方法

package.jsonに設定を記述しないと、server.jsを実行しようとするらしく、app.jsに処理を書いていたためこのようなエラーが出た。
そのため、以下のように設定して解決した。
Solve by writing start script in package.json.

{
  "name": "gcp-puppeteer",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
  },