Cloud Functions Firebase CLI 预部署错误(打字稿)
Cloud Functions Firebase CLI predeploy error (typescript)
我正在尝试使用 typescript 的 Cloud Functions。
安装成功后,添加触发器并测试部署。
index.ts
import * as functions from 'firebase-functions';
export const createAccount = functions.auth.user().onCreate(event => {
const user = event.data;
console.log('user displayname', user.displayName);
return;
});
命令
firebase deploy --only functions
=== Deploying to 'project'...
i deploying functions
i functions: running predeploy script.
> functions@ build D:\vmbox\project\firebase\functions
> tslint -p tslint.json && ./node_modules/.bin/tsc
错误
'.' is not recognized as an internal or external command,
operable program or batch file.
环境
firebase cli v3.16.0
节点 v6.11.2
npm v4.2.0
OS: Windows 10
终端:powershell
///
回滚到 Javascript
我使用 Javascript 选项重新启动函数,并且在部署时也出现错误。
我想这可能与 cli 为打字稿所做的设置有关。
必须删除添加到 "firebase.json" 的 "functions" 选项。
选项在firebase.json中删除:
"functions": {
"predeploy": "npm --prefix functions run build"
}
只需替换里面的package.json
这个
"build": "./node_modules/.bin/tslint.cmd -p tslint.json && ./node_modules/.bin/tsc.cmd"
在此
"build": ".\node_modules\.bin\tslint.cmd -p tslint.json && .\node_modules\.bin\tsc.cmd"
它将在 windows 上运行。
抱歉耽搁了。 Andrew 的回答会起作用,但它使项目现在只能在 Windows 上运行。更多信息,可以查看我的GitHub回答here。长话短说:
将 package.json 中的脚本更改为:
"scripts": {
"lint": "./node_modules/.bin/tslint -p tslint.json",
"build": "./node_modules/.bin/tsc"
}
将 firebase.json 中的预部署挂钩更改为:
{
"functions": {
"predeploy": "npm --prefix functions run lint && npm --prefix functions run build"
}
}
将此行添加到函数文件夹中的 tsconfig:
"typeRoots": [
"node_modules/@types"
],
这是 "compilerOptions" 块的一部分
为我工作
确保当你初始化项目时它要求你安装依赖项,你 select 是的,我想我必须手动编写依赖项所以我通过了它但它为你做了。当我这样做时,一切正常。我不知道这是否与它有关,但我还删除了节点模块文件夹,并在同一文件夹中从 firebase init 再次启动。
我正在尝试使用 typescript 的 Cloud Functions。
安装成功后,添加触发器并测试部署。
index.ts
import * as functions from 'firebase-functions';
export const createAccount = functions.auth.user().onCreate(event => {
const user = event.data;
console.log('user displayname', user.displayName);
return;
});
命令
firebase deploy --only functions
=== Deploying to 'project'...
i deploying functions
i functions: running predeploy script.
> functions@ build D:\vmbox\project\firebase\functions
> tslint -p tslint.json && ./node_modules/.bin/tsc
错误
'.' is not recognized as an internal or external command,
operable program or batch file.
环境
firebase cli v3.16.0
节点 v6.11.2
npm v4.2.0
OS: Windows 10
终端:powershell
///
回滚到 Javascript
我使用 Javascript 选项重新启动函数,并且在部署时也出现错误。
我想这可能与 cli 为打字稿所做的设置有关。
必须删除添加到 "firebase.json" 的 "functions" 选项。
选项在firebase.json中删除:
"functions": {
"predeploy": "npm --prefix functions run build"
}
只需替换里面的package.json
这个
"build": "./node_modules/.bin/tslint.cmd -p tslint.json && ./node_modules/.bin/tsc.cmd"
在此
"build": ".\node_modules\.bin\tslint.cmd -p tslint.json && .\node_modules\.bin\tsc.cmd"
它将在 windows 上运行。
抱歉耽搁了。 Andrew 的回答会起作用,但它使项目现在只能在 Windows 上运行。更多信息,可以查看我的GitHub回答here。长话短说:
将 package.json 中的脚本更改为:
"scripts": {
"lint": "./node_modules/.bin/tslint -p tslint.json",
"build": "./node_modules/.bin/tsc"
}
将 firebase.json 中的预部署挂钩更改为:
{
"functions": {
"predeploy": "npm --prefix functions run lint && npm --prefix functions run build"
}
}
将此行添加到函数文件夹中的 tsconfig:
"typeRoots": [
"node_modules/@types"
],
这是 "compilerOptions" 块的一部分 为我工作
确保当你初始化项目时它要求你安装依赖项,你 select 是的,我想我必须手动编写依赖项所以我通过了它但它为你做了。当我这样做时,一切正常。我不知道这是否与它有关,但我还删除了节点模块文件夹,并在同一文件夹中从 firebase init 再次启动。