question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cloud Function in Typescript

See original GitHub issue

The functions framework expect a index.js in the local directory. I’m writing my functions in Typescript and test it locally with nodemon, ts-node and a ts file, which starts the express server.

Is there a better way than running tsc every time something changes and then start the functions-framework?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
paulwoelfelcommented, Apr 10, 2019

My solution right now is to use tsc-watch and the following command:

npx tsc-watch --onSuccess 'npx @google-cloud/functions-framework --function-target=main --port=8080 --function-signature-type=http'

In the local directory I created index.js, which loads the transpiled js:

const cloudFunctions = require("./dist");

Object.keys(cloudFunctions).forEach(
  key => (exports[key] = cloudFunctions[key])
);

And that’s the tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "target": "es2018",
    "lib": ["dom", "es2018"],
    "module": "commonjs",
    "esModuleInterop": true,
    "pretty": true,
    "sourceMap": true
  },
  "include": ["./src/**/*"],
  "exclude": ["node_modules"]
}
5reactions
fernandofleurycommented, Aug 30, 2019

This is how I’m achieving it using nodemon:

{
  "start": "functions-framework --target=event",
  "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run watch-node\"",
  "watch-node": "nodemon --watch ./build/ --exec npm run start",
  "watch-ts": "tsc -w"
}

It’s a bit verbose I have to say, but it’s also following the official TS node boilerplate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Functions with TypeScript - Duffblog
Here's a small sample that uses TypeScript + Cloud Functions I have a complicated relationship with JavaScript. I'm old enough to remember ...
Read more >
Firebase Cloud Functions with Typescript and Webpack
Recently Firebase launched Cloud Functions–a way to run your code on their servers. It's a game changer! Now you can run code that...
Read more >
Building a REST API with Firebase cloud functions, TypeScript ...
In this article, you can learn how to build a REST API with Firebase cloud functions, TypeScript, and Firestore.
Read more >
How to define a Google Cloud Function with Typescript?
I am trying to setup a NodeJS function using Google Cloud Function (GCF) in typescript. I am trying to be strict with my...
Read more >
flatfisher/cloud-functions-typescript-template - GitHub
cloud-functions-typescript-template is a base project of Google Cloud Functions using TypeScript. This project contains tools and configuration files that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found