Cloud Functions Firebase CLI predeploy error (typescript)

本小妞迷上赌 提交于 2020-08-21 13:57:28

问题


I´m trying Cloud Functions with typescript.
After successfully installed, added a trigger and tested deploy.

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;
});

command

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

ERROR

'.' is not recognized as an internal or external command,
operable program or batch file.

Environment
firebase cli v3.16.0
node v6.11.2
npm v4.2.0
OS: Windows 10
terminal: powershell

///

Rollback to Javascript

I re-initiated functions with Javascript option, and also got errors when deploying.
I guess it may be related to a setup made by the cli for typescript.
Had to delete the "functions" option added to "firebase.json".

option deleted in firebase.json:

  "functions": {
    "predeploy": "npm --prefix functions run build"
  }

回答1:


Just replace inside the package.json this

"build": "./node_modules/.bin/tslint.cmd -p tslint.json && ./node_modules/.bin/tsc.cmd"

on this

"build": ".\\node_modules\\.bin\\tslint.cmd -p tslint.json && .\\node_modules\\.bin\\tsc.cmd"

and it will work on windows.




回答2:


add this line to tsconfig within the functions folder:

"typeRoots": [
  "node_modules/@types"
],

This is part of "compilerOptions" block worked for me




回答3:


Sorry for the delay. Andrew's answer will work, but it makes the project now only work on Windows. For more information, you can check my GitHub answer here. TL;DR:

Change the scripts in your package.json to:

  "scripts": {
    "lint": "./node_modules/.bin/tslint -p tslint.json",
    "build": "./node_modules/.bin/tsc"
  }

Change predeploy hook in your firebase.json to:

{
  "functions": {
    "predeploy": "npm --prefix functions run lint && npm --prefix functions run build"
  }
}



回答4:


Make sure that when you are initializing the project and it ask you to install dependencies, you select yes, I thought I had to manually write the dependencies so i passed it but it does it for you. When I did it everything worked. I don't know if this had something to do with it but i also deleted the node modules folder and in the same folder started again from firebase init.



来源:https://stackoverflow.com/questions/47756264/cloud-functions-firebase-cli-predeploy-error-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!