cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

Watch does not work on linux systems

Open jason0518 opened this issue 7 years ago • 2 comments

Environment details

  • OS: Ubuntu (latest at the time of writing this)
  • Node.js version: 8.10.0
  • npm version: 5.7.1
  • @google-cloud/functions-emulator version: 1.0.0-beta.4

Steps to reproduce

  1. Run any example/etc project on a linux system.
  2. Change a non node_module file in your function
  3. The function doesn't restart itself picking up your changes

Possible solution

  1. If you change src/supervisor/worker.js#L172 to watch a single file in your project (vs the recursive option) then it works as expected. If you checkout the Node docs there is a caveat for this as the recursive option only works on Mac or Windows.
  2. Perhaps using Chokidar to overcome these watch issues would be a good remedy

jason0518 avatar Mar 13 '18 16:03 jason0518

I've solved this issue locally with node-watch. Same API call, minimal change:

require('node-watch').(localdir, {
        recursive: true
      }, (event, filename) => {

ribizli avatar Jan 06 '19 15:01 ribizli

This worked for me, here are full instructions and a fix for @ribizli's small typo:

  • Find your @google-cloud directory, probably in your node_modules (see below for Firebase)
  • cd functions-emulator
  • Add node-watch: npm install --save node-watch
  • Edit the file src/supervisor/worker.js
  • Around line 180, you will find fs.watch(localdir, { . Replace this with require('node-watch')(localdir, { .

Using Firebase with typescript, all I have to do is run tsc -w in a separate terminal (the watch variant of npm run build). I can now change my source code and the emulator will notice the changes.

If you installed firebase globally, you can find these files by navigating to cd $(npm root -g)/firebase-tools/node_modules/@google-cloud.

dirkjot avatar Feb 23 '19 07:02 dirkjot