2017-10-19 291 views
6

我最近開始在嘗試部署到Firebase時發生以下錯誤(在過去成功完成之後)。我不確定可能會發生什麼變化以便開始發生。如果我運行Firebase服務在本地服務器上,一切正常。我的package.json和來自index.js的要求也在下面。FIrebase部署錯誤:無法找到模塊'firebase-admin'

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:

{ 
"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 
} 

從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 
); 
+0

剛開始得到相同的錯誤 –

回答

12

他們有一個積極的服務中​​斷。按照此一解決辦法:https://status.firebase.google.com/incident/Functions/17024

運行函數庫裏面以下命令:

npm install --save-exact [email protected] npm install --save-exact [email protected] 

然後再次嘗試部署功能:

firebase deploy --only functions 

如果NPM不起作用,你可以試試爲我們工作的紗線:

yarn add [email protected] --exact yarn add [email protected] --exact 
+0

我很沮喪,謝謝你! – user1819575

+0

它的工作原理!謝謝!並感謝紗線暗示! npm由於「Unsupported engine for [email protected]:wanted:{」node「:」〜0.10.12「}(current:{」node「:」6.11.1「,」npm「: 「5.5.1」})「 – Motin

+0

似乎固定在我身邊(挪威)...... npm和紗線解決方法都不適用於我。 –

2

更新文件package.json在文件夾功能查看相關刪除標誌〜從火力管理員和^從火力,功能應該是這樣:

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

在命令行中鍵入

npm install

,然後嘗試重新部署。

0

我也有同樣的錯誤。我修復了在nodejs中安裝不同版本的錯誤。我卸載了我的新版本,並且我安裝了節點v7.8.0。那麼它工作正常:)

0

我去功能目錄並跑了yarn(或npm install,如果你是老派)。然後回到我的項目目錄並再次運行firebase deploy