This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Run builds on file changes using watch with npm scripts

0:55 JavaScript lesson by

We can set up a file watcher to compile automatically while we develop. In this lesson we wire up a new dev script to run the build script when source files change.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

We can set up a file watcher to compile automatically while we develop. In this lesson we wire up a new dev script to run the build script when source files change.

Avatar
KMD A/S

I have an error while using npm run dev:

npm-package@1.0.0 dev C:\works\others\node.js\npm\create-npm-package

watch 'npm run build' src

Watching run
Watching build'
Watching src
C:\works\others\node.js\npm\create-npm-package\node_modules\watch\main.js:75
if (err) throw err;
^

Error: ENOENT: no such file or directory, stat 'C:\works\others\node.js\npm\create-npm-package\run'

npm ERR! Failed at the npm-package@1.0.0 dev script 'watch 'npm run build' src'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the npm-package package,
npm ERR! not with npm itself.

Node - 7.8.2
npm - 4.2.0

In reply to egghead.io
Avatar
Trevor

It may be an issue with the watch package on Windows. Try replacing this line https://github.com/trevordmiller/sensitive-words/blob/master/package.json#L7, with "dev": "babel src -d build --watch" and then run npm run dev again and let me know if that works :)

In reply to KMD A/S
Avatar
KMD A/S

This solution works for me :-) Thx a lot In meantime i installed npm-watch package that works without problem.

In reply to Trevor
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?