简体   繁体   English

Google App Engine - 节点:找不到模块'firebase-admin'

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

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 section). 首次在此部署GAE应用,我正在尝试按照本教程进行操作: https//firebase.googleblog.com/2016/08/sending-notifications-between-android.html (请参阅节点代码部分)。

I ran 我跑了

npm install firebase-admin --save
npm install request --save

on my machine, the package.json is here, but when I use gcloud app deploy , I get these logs when opening the app on my browser: 在我的机器上,package.json就在这里,但是当我使用gcloud app deploy ,我在浏览器上打开应用程序时会得到这些日志:

2017-02-10 09:35:02 default[20170210t103151]  module.js:471
2017-02-10 09:35:02 default[20170210t103151]      throw err;
2017-02-10 09:35:02 default[20170210t103151]      ^
2017-02-10 09:35:02 default[20170210t103151]
2017-02-10 09:35:02 default[20170210t103151]  Error: Cannot find module 'firebase-admin'
2017-02-10 09:35:02 default[20170210t103151]      at Function.Module._resolveFilename (module.js:469:15)
2017-02-10 09:35:02 default[20170210t103151]      at Function.Module._load (module.js:417:25)
2017-02-10 09:35:02 default[20170210t103151]      at Module.require (module.js:497:17)
2017-02-10 09:35:02 default[20170210t103151]      at require (internal/module.js:20:19)
2017-02-10 09:35:02 default[20170210t103151]      at Object.<anonymous> (/app/server.js:1:78)
2017-02-10 09:35:02 default[20170210t103151]      at Module._compile (module.js:570:32)
2017-02-10 09:35:02 default[20170210t103151]      at Object.Module._extensions..js (module.js:579:10)
2017-02-10 09:35:02 default[20170210t103151]      at Module.load (module.js:487:32)
2017-02-10 09:35:02 default[20170210t103151]      at tryModuleLoad (module.js:446:12)
2017-02-10 09:35:02 default[20170210t103151]      at Function.Module._load (module.js:438:3)
2017-02-10 09:35:07 default[20170210t103151]  module.js:471
2017-02-10 09:35:07 default[20170210t103151]      throw err;
2017-02-10 09:35:07 default[20170210t103151]      ^
2017-02-10 09:35:07 default[20170210t103151]
2017-02-10 09:35:07 default[20170210t103151]  Error: Cannot find module 'firebase-admin'
2017-02-10 09:35:07 default[20170210t103151]      at Function.Module._resolveFilename (module.js:469:15)
2017-02-10 09:35:07 default[20170210t103151]      at Function.Module._load (module.js:417:25)
2017-02-10 09:35:07 default[20170210t103151]      at Module.require (module.js:497:17)
2017-02-10 09:35:07 default[20170210t103151]      at require (internal/module.js:20:19)
2017-02-10 09:35:07 default[20170210t103151]      at Object.<anonymous> (/app/server.js:1:78)
2017-02-10 09:35:07 default[20170210t103151]      at Module._compile (module.js:570:32)
2017-02-10 09:35:07 default[20170210t103151]      at Object.Module._extensions..js (module.js:579:10)
2017-02-10 09:35:07 default[20170210t103151]      at Module.load (module.js:487:32)
2017-02-10 09:35:07 default[20170210t103151]      at tryModuleLoad (module.js:446:12)
2017-02-10 09:35:07 default[20170210t103151]      at Function.Module._load (module.js:438:3)
2017-02-10 09:43:58 default[20170210t104151]  module.js:471
2017-02-10 09:43:58 default[20170210t104151]      throw err;
2017-02-10 09:43:58 default[20170210t104151]      ^
2017-02-10 09:43:58 default[20170210t104151]
2017-02-10 09:43:58 default[20170210t104151]  Error: Cannot find module 'serviceAccountKey.json'
2017-02-10 09:43:58 default[20170210t104151]      at Function.Module._resolveFilename (module.js:469:15)
2017-02-10 09:43:58 default[20170210t104151]      at Function.Module._load (module.js:417:25)
2017-02-10 09:43:58 default[20170210t104151]      at Module.require (module.js:497:17)
2017-02-10 09:43:58 default[20170210t104151]      at require (internal/module.js:20:19)
2017-02-10 09:43:58 default[20170210t104151]      at Object.<anonymous> (/app/server.js:7:22)
2017-02-10 09:43:58 default[20170210t104151]      at Module._compile (module.js:570:32)
2017-02-10 09:43:58 default[20170210t104151]      at Object.Module._extensions..js (module.js:579:10)
2017-02-10 09:43:58 default[20170210t104151]      at Module.load (module.js:487:32)
2017-02-10 09:43:58 default[20170210t104151]      at tryModuleLoad (module.js:446:12)
2017-02-10 09:43:58 default[20170210t104151]      at Function.Module._load (module.js:438:3)
2017-02-10 09:44:10 default[20170210t104151]  module.js:471
2017-02-10 09:44:10 default[20170210t104151]      throw err;
2017-02-10 09:44:10 default[20170210t104151]      ^
2017-02-10 09:44:10 default[20170210t104151]
2017-02-10 09:44:10 default[20170210t104151]  Error: Cannot find module 'serviceAccountKey.json'
2017-02-10 09:44:10 default[20170210t104151]      at Function.Module._resolveFilename (module.js:469:15)
2017-02-10 09:44:10 default[20170210t104151]      at Function.Module._load (module.js:417:25)
2017-02-10 09:44:10 default[20170210t104151]      at Module.require (module.js:497:17)
2017-02-10 09:44:10 default[20170210t104151]      at require (internal/module.js:20:19)
2017-02-10 09:44:10 default[20170210t104151]      at Object.<anonymous> (/app/server.js:7:22)
2017-02-10 09:44:10 default[20170210t104151]      at Module._compile (module.js:570:32)
2017-02-10 09:44:10 default[20170210t104151]      at Object.Module._extensions..js (module.js:579:10)
2017-02-10 09:44:10 default[20170210t104151]      at Module.load (module.js:487:32)
2017-02-10 09:44:10 default[20170210t104151]      at tryModuleLoad (module.js:446:12)
2017-02-10 09:44:10 default[20170210t104151]      at Function.Module._load (module.js:438:3)
2017-02-10 16:20:02 default[20170210t124920]  Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "connect ETIMEDOUT 74.125.202.84:443".
2017-02-10 16:20:02 default[20170210t124920]      at /app/node_modules/firebase-admin/lib/firebase-app.js:74:23
2017-02-10 16:20:02 default[20170210t124920]      at process._tickCallback (internal/process/next_tick.js:103:7)

How do I fix this ?? 我该如何解决 ??

These issues seem to be caused by a misunderstanding of how require() paths work. 这些问题似乎是由于对require()路径如何工作的误解造成的。 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. 您不能使用绝对路径,因为当部署应用程序并导入失败时,远程计算机上显然不存在require("/Users/username/somepath") Using require("serviceAccountKey.json") is going to look in node_modules/serviceAccountKey.json relative to the app directory. 使用require("serviceAccountKey.json")将查看相对于app目录的node_modules / serviceAccountKey.json

If you want to load serviceAccountKey.json from the app's root directory, you would use require("./serviceAccountKey.json") . 如果要从应用程序的根目录加载serviceAccountKey.json ,可以使用require("./serviceAccountKey.json") If it were in a subdirectory called foo under the root you'd use require("./foo/serviceAccountKey.json") . 如果它位于根目录下名为foo的子目录中,则使用require("./foo/serviceAccountKey.json") This also applies to loading modules in general such as firebase-admin . 这也适用于加载模块,例如firebase-admin

The NodeJS Modules documentation explains the require() mechanism in greater detail. NodeJS模块文档更详细地解释了require()机制。

I could make a workaround on this proceeding like this: (passing the serviceAccountkeyFile.json parameters inside app.js code): 我可以像这样对这个过程做一个解决方法:(在app.js代码中传递serviceAccountkeyFile.json参数):

let defaultAppConfig = {
    credential: admin.credential.cert({
        type: "service_account",
        project_id: "txxxxxxxxxx",
        private_key_id: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
        private_key: "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----\n",
        client_email: "firebaxxxxxxx@xxxxxxx.gserviceaccount.com",
        client_id: "11111111111111111",
        auth_uri: "https://accounts.google.com/o/oauth2/auth",
        token_uri: "https://accounts.google.com/o/oauth2/token",
        auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
        client_x509_cert_url: "https://www.googleapis.com/robot/v1/metadata/x509/jjjjjj.gserviceaccount.com"
    }),
    databaseURL: 'https://projectxxx.firebaseio.com/'
}

defaultApp = admin.initializeApp(defaultAppConfig);

I had a similar problem running gcloud app deploy 我在运行gcloud app deploy遇到了类似的问题

Error: Cannot find module 'webpack-dev-server'
at Function.Module._resolveFilename (module.js:469:15)

I solved the issue moving the given dependency (wepack-dev-server) from devDependencies to dependencies in package.json . 我解决了将给定依赖项(wepack-dev-server)从devDependenciespackage.json dependencies问题。

In case somebody else has the same problem I suggest to have look at your dependencies in package.json . 如果其他人有同样的问题,我建议你在package.json查看你的依赖项。 dependencies are required to run, devDependencies only to develop, eg: unit tests, Coffeescript to Javascript transpilation, minification, 运行时需要dependenciesdevDependencies只用于开发,例如:单元测试,Coffeescript到Javascript的编译,缩小,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“firebase-admin” - Cannot find module 'firebase-admin' Firebase功能部署错误找不到模块firebase-admin - Firebase function deploy error cannot find module firebase-admin 谷歌云平台:“找不到模块firebase-admin” - google cloud platform: “Can't find module firebase-admin” Cloud Functions for Firebase firebase 部署错误:“解析触发器时出错:找不到模块‘firebase-admin’” - Cloud Functions for Firebase firebase deploy error: "Error parsing triggers: Cannot find module 'firebase-admin'" 将Node.js应用程序部署到Google App Engine时出现“找不到模块” - “Cannot find module” when deploying Node.js app to Google App Engine Firebase 在运行 firebase 服务时找不到“firebase-admin”模块 - Firebase cannot found the 'firebase-admin' module when run firebase serve 错误:在谷歌应用引擎上部署 node.js 后找不到模块“/workspace/server.js” - Error: Cannot find module '/workspace/server.js' upon node js deploy on google app engine Nodejs firebase-admin使用Google Kubernetes引擎中的应用程序默认凭据进行身份验证 - Nodejs firebase-admin authenticate with application default credentials in Google Kubernetes engine Google App Engine - 引擎“节点”与此模块不兼容 - Google App Engine - The engine "node" is incompatible with this module 在谷歌应用引擎上运行 firebase admin 和 firestore - Running firebase admin and firestore on google app engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM