[英]React + Firebase Cloud Functions in Typescript fails to deploy
[英]Firebase function fails to deploy from visual studio due to mysterious syntax errors (see screenshot or screen recording)
當我部署我的 firebase function 時,由於似乎是語法問題,部署失敗。 請參閱屏幕截圖中的終端 window。 錯誤主要包括“字符串必須是雙引號”和“預期縮進 8 個空格但找到 2 個制表符”。 在 VisualStudio IDE 中,我看不到這些錯誤,所以我試圖弄清楚為什么當我嘗試將此 function 部署到 Z035489FF8D092741943E4A8324 時會出現這些錯誤。
我在 Visual Studio 中使用 Typescript 並通過終端中的firebase deploy --only functions
命令部署到 Firebase。
端子 Output:
(base) samyoon@Sams-MBP FitnessApp % firebase deploy --only functions
=== Deploying to 'fitnessapp-b3eea'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
lint
eslint --ext .js,.ts .
/Users/samyoon/Documents/FitnessApp/functions/src/index.ts
1:19 error Require statement not part of import statement @typescript-eslint/no-var-requires
1:27 error Strings must use doublequote quotes
2:15 error Require statement not part of import statement @typescript-eslint/no-var-requires
2:23 error Strings must use doublequote quotes
4:16 error Strings must use doublequote quotes
7:15 error Strings must use doublequote quotes
8:22 warning 'context' is defined but never used @typescript-eslint/no-unused-vars
14:1 error Unexpected tab character no-tabs
14:1 error Mixed spaces and tabs no-mixed-spaces-and-tabs
17:1 error Unexpected tab character no-tabs
17:1 error Mixed spaces and tabs no-mixed-spaces-and-tabs
18:1 error Unexpected tab character no-tabs
18:1 error Expected indentation of 8 spaces but found 2 tabs indent
19:1 error Unexpected tab character no-tabs
19:1 error Expected indentation of 8 spaces but found 2 tabs indent
19:9 error Strings must use doublequote quotes
20:1 error Unexpected tab character no-tabs
20:1 error Expected indentation of 8 spaces but found 2 tabs indent
20:9 error Strings must use doublequote quotes
21:1 error Unexpected tab character no-tabs
21:1 error Expected indentation of 6 spaces but found 1 tab indent
21:4 error Missing semicolon semi
✖ 22 problems (21 errors, 1 warning)
11 errors and 0 warnings potentially fixable with the `--fix` option.
Error: functions predeploy error: Command terminated with non-zero exit code 1
代碼:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
import {} from 'firebase-admin';
exports.createUser = functions.firestore
.document('users/{userId}')
.onCreate((snap, context) => {
// Get an object representing the document
// e.g. {'name': 'Marie', 'age': 66}
const userData = snap.data();
// access a particular field as you would any JS property
const userUID = userData.uid;
// perform desired operations ... create new WorkoutCycle document
admin.collection("WorkoutCycles").doc().set({
createdTimestamp: Date.now(),
name: 'FunctionCreatedMe',
user: 'users/'+userUID,
})
});
這是該問題的屏幕錄像: https://www.loom.com/share/881de3fe7e2f45ccb4f99155b69c5bea
這是問題的屏幕截圖:Visual Studio IDE 和終端的屏幕截圖
我能夠解決這個問題。 我去了我的 firebase.json 文件,它看起來像這樣:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
並刪除了這部分:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
之后我使用以下命令部署了我的 function:
firebase deploy --only functions
我的 function 成功部署到 Firebase 並且我可以在控制台中看到它。
盡管用例不同,但這篇 github 帖子有助於發現解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.