我只是尝试使用Firebase云功能。 index.ts只是一个世界。但是部署firebase云功能时出现错误。
我只是从这里开始观看视频教程:https://www.youtube.com/watch?v=DYfP-UIKxH0
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/muchammadagunglaksana/Documents/Latihan/cloud_function/doug_youtube/functions
> tslint --project tsconfig.json
Running command: npm --prefix "$RESOURCE_DIR" run build
> functions@ build /Users/muchammadagunglaksana/Documents/Latihan/cloud_function/doug_youtube/functions
> tsc
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from 'firebase-functions';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/muchammadagunglaksana/.npm/_logs/2019-09-09T03_21_14_265Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
Muchammads-MacBook-Air:doug_youtube muchammadagunglaksana$
这是索引。ts
import * as functions from 'firebase-functions';
// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
这是我的package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.1.0"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}
我该怎么办?
答案 0 :(得分:1)
我怀疑您在部署之前没有保存源文件。在磁盘上,该功能可能仍被注释掉,这将导致functions
处于未使用状态。
答案 1 :(得分:0)
问题与新版本的打字稿有关,只需从tsconfig.json“ noUnusedLocals”禁用此属性即可:false
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
] }