cloud-functions-emulator
cloud-functions-emulator copied to clipboard
Watch does not work on linux systems
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
- Run any example/etc project on a linux system.
- Change a non node_module file in your function
- The function doesn't restart itself picking up your changes
Possible solution
- If you change
src/supervisor/worker.js#L172to 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. - Perhaps using Chokidar to overcome these watch issues would be a good remedy
I've solved this issue locally with node-watch. Same API call, minimal change:
require('node-watch').(localdir, {
recursive: true
}, (event, filename) => {
This worked for me, here are full instructions and a fix for @ribizli's small typo:
- Find your
@google-clouddirectory, probably in yournode_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 withrequire('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.