FIrebase部署错误:无法找到模块'firebase-admin'

时间:2021-09-17 20:17:18

I recently started getting the error below when trying to deploy to Firebase (after having done so successfully in the past). I'm not sure what might have changed for this to start occurring. If I run firebase serve to serve on the localhost, everything works fine. My package.json and requires from index.js are also below.

我最近在尝试部署到Firebase时开始收到以下错误(过去成功完成之后)。我不确定这可能会有什么变化才能开始发生。如果我运行firebase服务在localhost上服务,一切正常。我的package.json和index.js的需求也在下面。

i  deploying functions, hosting
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
+  runtimeconfig: all necessary APIs are enabled
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (46.02 KB) for uploading
+  functions: functions folder uploaded successfully
i  hosting: preparing public directory for upload...
!  Warning: Public directory does not contain index.html
+  hosting: 9 files uploaded successfully
i  starting release process (may take several minutes)...
i  functions: updating function app...
!  functions[app]: Deploy Error: Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-admin'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/apps.j
s:25:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)


Functions deploy had errors. To continue deploying other features (such as datab
ase), run:
firebase deploy --except functions

Error: Functions did not deploy properly.

package.json:

的package.json:

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"@google-cloud/vision": "^0.12.0",
"async": "^2.5.0",
"consolidate": "^0.14.5",
"express": "^4.15.4",
"firebase-admin": "^5.4.0",
"firebase-functions": "^0.5.7",
"handlebars": "^4.0.10",
"jquery": "^3.2.1",
"js-levenshtein": "^1.1.3",
"json-query": "^2.2.2"
},
"private": true
}

From index.js:

来自index.js:

const functions = require('firebase-functions');
const firebase = require('firebase-admin');
const express = require('express');
const engines = require('consolidate');
const Vision = require('@google-cloud/vision');
const levenshtein = require('js-levenshtein');
const restName = require('./restName');
const parser = require('./parser');
const jsonQuery = require('json-query')

const firebaseApp = firebase.initializeApp(
functions.config().firebase
);

4 个解决方案

#1


17  

They have an active service disruption. Follow this for a workaround: https://status.firebase.google.com/incident/Functions/17024

他们有一个积极的服务中​​断。请按照以下方法获取解决方法:https://status.firebase.google.com/incident/Functions/17024

Run the following commands inside the functions repository:

在函数库中运行以下命令:

npm install --save-exact firebase-functions@0.7.0 npm install --save-exact firebase-admin@5.4.0

Then try deploying functions again:

然后再尝试部署函数:

firebase deploy --only functions

If npm doesn't work, you can try yarn which worked for us:

如果npm不起作用,你可以试试为我们工作的纱线:

yarn add firebase-functions@0.7.0 --exact yarn add firebase-admin@5.4.0 --exact

#2


2  

Update file package.json in folder functions and look at dependencies remove sign ~ from firebase-admin and ^ from firebase-functions it should be like:

在文件夹函数中更新文件package.json并查看依赖项从firebase-admin删除sign~和firebase函数中的^应该是这样的:

"dependencies": {
  "firebase-admin": "5.4.0",
  "firebase-functions": "0.7.0"
}

in command line type

在命令行类型中

npm install

npm安装

and then try to deploy again.

然后再次尝试部署。

#3


0  

I also got same error. i fix that error from installing different version in nodejs. I uninstall my new version and i install Node v7.8.0. then it works fine :)

我也有同样的错误。我修复了在nodejs中安装不同版本的错误。我卸载了我的新版本,然后安装了Node v7.8.0。然后它工作正常:)

#4


0  

I went to the functions directory and ran yarn (or npm install if you are old-school). Then went back to my project directory and ran firebase deploy again.

我去了函数目录并运行了yarn(如果你是老派的话,还是npm install)。然后回到我的项目目录并再次运行firebase部署。

#1


17  

They have an active service disruption. Follow this for a workaround: https://status.firebase.google.com/incident/Functions/17024

他们有一个积极的服务中​​断。请按照以下方法获取解决方法:https://status.firebase.google.com/incident/Functions/17024

Run the following commands inside the functions repository:

在函数库中运行以下命令:

npm install --save-exact firebase-functions@0.7.0 npm install --save-exact firebase-admin@5.4.0

Then try deploying functions again:

然后再尝试部署函数:

firebase deploy --only functions

If npm doesn't work, you can try yarn which worked for us:

如果npm不起作用,你可以试试为我们工作的纱线:

yarn add firebase-functions@0.7.0 --exact yarn add firebase-admin@5.4.0 --exact

#2


2  

Update file package.json in folder functions and look at dependencies remove sign ~ from firebase-admin and ^ from firebase-functions it should be like:

在文件夹函数中更新文件package.json并查看依赖项从firebase-admin删除sign~和firebase函数中的^应该是这样的:

"dependencies": {
  "firebase-admin": "5.4.0",
  "firebase-functions": "0.7.0"
}

in command line type

在命令行类型中

npm install

npm安装

and then try to deploy again.

然后再次尝试部署。

#3


0  

I also got same error. i fix that error from installing different version in nodejs. I uninstall my new version and i install Node v7.8.0. then it works fine :)

我也有同样的错误。我修复了在nodejs中安装不同版本的错误。我卸载了我的新版本,然后安装了Node v7.8.0。然后它工作正常:)

#4


0  

I went to the functions directory and ran yarn (or npm install if you are old-school). Then went back to my project directory and ran firebase deploy again.

我去了函数目录并运行了yarn(如果你是老派的话,还是npm install)。然后回到我的项目目录并再次运行firebase部署。