Google App Engine - Node: Cannot find module 'firebase-admin'

前端 未结 3 1123
悲哀的现实
悲哀的现实 2021-02-05 13:06

First time deploying a GAE app here, I\'m trying to follow this tutorial: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html (see node code secti

3条回答
  •  旧巷少年郎
    2021-02-05 13:21

    These issues seem to be caused by a misunderstanding of how require() paths work. You cannot use an absolute path because something like require("/Users/username/somepath") obviously won't exist on the remote machine when the app is deployed and the import will fail. Using require("serviceAccountKey.json") is going to look in node_modules/serviceAccountKey.json relative to the app directory.

    If you want to load serviceAccountKey.json from the app's root directory, you would use require("./serviceAccountKey.json"). If it were in a subdirectory called foo under the root you'd use require("./foo/serviceAccountKey.json"). This also applies to loading modules in general such as firebase-admin.

    The NodeJS Modules documentation explains the require() mechanism in greater detail.

提交回复
热议问题