Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

ionic serve crashes on file change (>= 0.0.47) #535

Closed
chriswep opened this issue Dec 13, 2016 · 10 comments
Closed

ionic serve crashes on file change (>= 0.0.47) #535

chriswep opened this issue Dec 13, 2016 · 10 comments

Comments

@chriswep
Copy link

initial build works fine. as soon as i change a code file i puts out "build started ..." and immediately after that:

(node:23058) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'send' of undefined
(node:23058) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

After that i halts there, doing nothing else. The watcher still runs, subsequent file changes result in the same behaviour.
This issue appeared right after i updated from 0.0.46 to 0.0.47

I run Node 7 if that matters.

@larssn
Copy link

larssn commented Dec 13, 2016

Tried removing node_modules and doing a fresh npm install?

@danbucholtz
Copy link
Contributor

danbucholtz commented Dec 14, 2016

@metzc,

Can you run ionic serve --debug and see if there is anything interesting going on? That should at least print out a stack trace. I need more info to go off of here.

Thanks,
Dan

@chriswep
Copy link
Author

chriswep commented Dec 14, 2016

sure:

[ DEBUG! ]  watch callback start, id: 2, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/services/user.service.ts  MEM: 770.9MB 
[ DEBUG! ]  watch callback complete, id: 2, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/services/user.service.ts  MEM: 768.8MB 
[16:53:41]  build started ... MEM: 729.6MB 
[ DEBUG! ]  Emitting event BuildUpdateStarted  MEM: 728.5MB 
(node:57194) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'send' of undefined

that is the output if i change a TypeScript file. I noticed now that if i change index.html there seems to be an additional callback:

[ DEBUG! ]  watch callback start, id: 0, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 34.1MB 
[ DEBUG! ]  watch callback start, id: 0, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 34.5MB 
[ DEBUG! ]  watch callback complete, id: 0, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 34.5MB 
[ DEBUG! ]  watch callback complete, id: 1, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 34.6MB 
[16:51:06]  build started ... MEM: 35.0MB 
[ DEBUG! ]  Emitting event BuildUpdateStarted  MEM: 35.1MB 
[16:51:06]  copy update started ... MEM: 37.5MB 
[ DEBUG! ]  copyUpdate, event: change, path: /Users/chris/Sites/emmaus-app/src/index.html  MEM: 37.8MB 
(node:56895) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'send' of undefined
(node:56895) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[ DEBUG! ]  Emitting event FileChange  MEM: 44.6MB 
[16:51:06]  copy update finished in 55 ms MEM: 45.2MB 

also, on a subsequent change of index.html (and contrary to a TS change) this appears:

[ DEBUG! ]  watch callback start, id: 2, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 48.4MB 
[ DEBUG! ]  watch callback start, id: 2, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 48.4MB 
[ DEBUG! ]  watch callback complete, id: 2, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 48.4MB 
[ DEBUG! ]  watch callback complete, id: 3, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 48.4MB 
[16:51:27]  build started ... MEM: 48.4MB 
[ DEBUG! ]  Emitting event BuildUpdateStarted  MEM: 48.4MB 
[16:51:27]  copy update started ... MEM: 48.4MB 
[ DEBUG! ]  copyUpdate, event: change, path: /Users/chris/Sites/emmaus-app/src/index.html  MEM: 48.5MB 
(node:56895) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'send' of undefined
[ DEBUG! ]  Emitting event FileChange  MEM: 53.9MB 
[16:51:27]  copy update finished in 32 ms MEM: 53.9MB 
[16:51:27]  error sending client ws - Cannot read property 'readyState' of undefined  MEM: 62.0MB
[16:51:27]  error sending client ws - Cannot read property 'readyState' of undefined  MEM: 62.0MB

Furthermore, the next change to index.html seems to complete random steps of previous attempts to build, as far as i can see, it changes on every run:

[ DEBUG! ]  watch callback start, id: 4, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 99.7MB 
[ DEBUG! ]  watch callback start, id: 4, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 99.7MB 
[ DEBUG! ]  watch callback complete, id: 4, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 99.7MB 
[ DEBUG! ]  watch callback complete, id: 5, isProd: false, event: change, path: 
            /Users/chris/Sites/emmaus-app/src/index.html  MEM: 99.7MB 
[16:51:56]  build started ... MEM: 99.8MB 
[ DEBUG! ]  Emitting event BuildUpdateStarted  MEM: 99.9MB 
[16:51:56]  copy update started ... MEM: 100.2MB 
[ DEBUG! ]  copyUpdate, event: change, path: /Users/chris/Sites/emmaus-app/src/index.html  MEM: 100.3MB 
[16:51:56]  template update started ... MEM: 166.3MB 
[ DEBUG! ]  templateUpdate, updated: /Users/chris/Sites/emmaus-app/src/index.html  MEM: 166.4MB 
[16:51:56]  template update finished in 135 ms MEM: 166.4MB 
[ DEBUG! ]  Emitting event BuildUpdateCompleted  MEM: 166.4MB 
[16:51:56]  build finished in 170 ms MEM: 166.4MB 

[ DEBUG! ]  Emitting event FileChange  MEM: 167.5MB 
[16:51:56]  copy update finished in 172 ms MEM: 167.5MB 

sometime it does a "build finished", sometimes only a "transpile started / finished" but it seems like random build steps that are triggered by a file change.

So it seems to me there is something off with some async code.

@danbucholtz
Copy link
Contributor

danbucholtz commented Dec 14, 2016

I don't think there's anything off necessarily WRT to async flows. It's all chained together via Promises. Are you using any options, or just straight ionic serve? Is your browser open or opening correctly?

We haven't seen this at all. Are you on Mac OS? Seems like it from the paths.

What node version? We test in 4 and 6 LTS.

Thanks,
Dan

@chriswep
Copy link
Author

chriswep commented Dec 15, 2016

i was originally running node 7.0.0. tried now with 0.6.7 and 7.2.1.
tried rebuilding node_modules
tried app-scripts nightly

same behaviour

I always run ionic serve with "-b". Because you asked i ran it without and voila! Issue dissappears. Tried two times, did the same change. When running with "-b" it goes bonkers, without it works just fine. Seems very strange to me.

update: though it works without an error, i still get somewhat weird console output in that the message copy update finished appears after build finished

@chriswep chriswep changed the title ionic serve crashes on file change (0.0.47) ionic serve crashes on file change (0.0.48) Dec 20, 2016
@chriswep
Copy link
Author

issue remains on 0.0.48. i looked into it with the debugger which reveals that it breaks at notification-server.js at line 20

    function drainMessageQueue(options) {
        if (options === void 0) { options = { broadcast: false }; }
        var sendMethod = wsServer.send;

wsServer is undefined.

@thinktinker
Copy link

thinktinker commented Dec 20, 2016

Edit: Any solution to this issue yet? I'm using 0.0.47 with node 6.9.1 on a Mac OS (should be ubuntu, I'm running in a virtual machine on my mac OS). Still getting the same errors as the folks here.

Used ionic serve, ionic serve -all. Both do not work. =S

@chriswep chriswep changed the title ionic serve crashes on file change (0.0.48) ionic serve crashes on file change (>= 0.0.47) Dec 20, 2016
@danbucholtz
Copy link
Contributor

@metzc, wanna fix it and do a PR? I am very focused on bundle sizes right now.

Thanks,
Dan

@chriswep
Copy link
Author

@danbucholtz i had a quick look into it and it seems to me that wsServer is used before we can be sure that it has been assigned (which happens at the async event wss.onConnection). The issue was introduced about two weeks ago in this commit: 62d6b23 (by removing the condition if the wss server is ready). @jthoms1 maybe you have a look because very likely there was a reason you removed the condition?

@danbucholtz
Copy link
Contributor

This should be fixed now. Will be published tomorrow in 0.0.49.

Please let me know if it's not.

Thanks,
Dan

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants