简体   繁体   English

FIrebase 部署错误:找不到模块“firebase-admin”

[英]FIrebase deploy error: Cannot find module 'firebase-admin'

I recently started getting the error below when trying to deploy to Firebase (after having done so successfully in the past).我最近在尝试部署到 Firebase 时开始收到以下错误(在过去成功完成之后)。 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.如果我运行 firebase serve 在本地主机上服务,一切正常。 My package.json and requires from index.js are also below.我的 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
);

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:

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

在此处输入图片说明

So the issue is that package.json inside Functions folder is different from package.json in your project directory.所以,问题是职能内部的文件夹的package.json从项目目录中的package.json不同。 yes, you have 2 of this file!是的,你有 2 个这个文件!

So if you want to deploy, (deploy Functions), run npm install express or install other dependencies inside Function folder and you will be able to deploy with no error.因此,如果您想部署(部署 Functions),请运行 npm install express 或在 Function 文件夹中安装其他依赖项,您将能够毫无错误地进行部署。

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 和 ^ 中删除符号 ~ 从 firebase-functions 它应该是这样的:

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

in command line type在命令行类型

npm install安装

and then try to deploy again.然后再次尝试部署。

I went to the functions directory and ran yarn (or npm install if you are old-school).我转到函数目录并运行yarn (或者npm install如果你是老派)。 Then went back to my project directory and ran firebase deploy again.然后回到我的项目目录并再次运行firebase deploy

运行以下命令

npm i firebase-admin 

I also got same error.我也遇到了同样的错误。 i fix that error from installing different version in nodejs.我通过在 nodejs 中安装不同版本来修复该错误。 I uninstall my new version and i install Node v7.8.0 .我卸载了我的新版本并安装了Node v7.8.0 then it works fine :)然后它工作正常:)

Try installing: npm i -g firebase-tools@6.8.0尝试安装: npm i -g firebase-tools@6.8.0

This solved my issue.这解决了我的问题。

If using docker, ensure your local version of nodejs is the same as the one you are using on the docker file.如果使用 docker,请确保您本地的 nodejs 版本与您在 docker 文件上使用的版本相同。 For example, if I am using node v16.14.0, (find out by typing this in your terminal) node -v , then sample docker file should be:例如,如果我使用的是 node v16.14.0,(通过在终端中输入它来查找) node -v ,那么示例 docker 文件应该是:

FROM node:16.14.0-alpine                             
ENV NODE_ENV=production                 
WORKDIR /app                            
COPY package*.json ./                  
RUN npm install --production            
COPY . .                                
CMD [ "npm", "start" ] 

             

The things I did to fix this我为解决这个问题所做的事情

1.) Make sure I was in the proper directory's package.json 1.) 确保我在正确的目录中 package.json

2.) rm -rf node-modules 2.) rm -rf node-modules

3.) npm i (missing module) 3.) npm i (missing module)

4.) Made the missing dependencies were NOT in devDependencies but rather in dependencies in the package.json, nothing in devDependencies gets deployed 4.) 使缺少的依赖项不在devDependencies中,而是在 package.json 中的dependencies项中, devDependencies中没有任何内容被部署

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM