SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sample code form Chapter 5 on up doesn't work: Can't set headers

    I have worked my way successfully all the way to Chapter 5 without any problems.
    However, now I can't get the Chapter 5 code to run. I at first was looking for something wrong in my transcription of the code from book to editor but when I attempted to run the code I downloaded from the website I failed as well.
    To be specific I get:
    Code:
    info  - socket.io started
    
    http.js:708
        throw new Error('Can\'t set headers after they are sent.');
              ^
    Error: Can't set headers after they are sent.
        at ServerResponse.OutgoingMessage.setHeader (http.js:708:11)
        at ServerResponse.res.setHeader (/home/puffjay/Sandbox/Node/chapter05/node_modules/express/node_modules/connect/lib/patch.js:62:20)
        at next (/home/puffjay/Sandbox/Node/chapter05/node_modules/express/node_modules/connect/lib/http.js:171:13)  
        at /home/puffjay/Sandbox/Node/chapter05/node_modules/express/node_modules/connect/lib/middleware/static.js:150:11
        at Object.oncomplete (fs.js:107:15)
    The error occurs and crashes the page right away.
    From googling, it appears that this error is a bit of a tricky one to pin down.
    Can anyone else confirm that they are getting the error?

    When I run the demo code, I run "npm install" in the base chapter05 directory and after that completes, I run "node nockmarket.js" with my local mongodb instance running. I do receive some warnings during the npm install but most are simple complaints about a missing README.md file with these others:
    Code:
    npm WARN engine hawk@0.10.2: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    npm WARN engine hoek@0.7.3: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    npm WARN engine boom@0.3.8: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    npm WARN engine formidable@1.0.13: wanted: {"node":"<0.9.0"} (current: {"node":"v0.10.2","npm":"1.2.15"})
    OS: Arch Linux

    Are there any other details that may help get to the bottom of this mystery?

  2. #2
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the answer to the problem.
    There have been several breaking changes to node that broke the sockets.io portion of the code.
    I needed to use an older version of node. I therefore installed nvm, the node version manager and installed v0.8.22.
    I then needed to delete my node_modules directory and reperform the node install.
    However, my system's python points to python3 and not python2. This was a problem for node-gyp.
    I therefore had to run "node install --python=/usr/bin/python2". After the install all worked nicely.

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just wanted to "me too" this thread. I experienced the errors with the version of node I had (0.10.x) and using nvm to use 0.8.26 solved the issue.

    This of course leads me to want to know what I need to change to get it working with node >= 0.10 as any new projects I do will use 0.10.

  4. #4
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nkloster View Post
    I found the answer to the problem.
    There have been several breaking changes to node that broke the sockets.io portion of the code.
    I needed to use an older version of node. I therefore installed nvm, the node version manager and installed v0.8.22.
    I then needed to delete my node_modules directory and reperform the node install.
    However, my system's python points to python3 and not python2. This was a problem for node-gyp.
    I therefore had to run "npm install --python=/usr/bin/python2". After the install all worked nicely.
    Correction in bold.

    This, unfortunately, did not work for me as I do not have python 2 on my system (current version of Mac OS X Mavericks) and could not get npm install to run... The lowest version I have on my system is 2.5 and that would not allow node-gyp to run. I don't really want to fight any more with this to get it working and will probably just bypass the 'chat' component of the application to continue on.

    Regardless, I am with Tinjaw however, I would think it would be possible to run sockets.io within a node 0.10.xx install since they should be capable playing nicely together. I don't know if I have the inclination to try to debug this issue, but I am wondering if anyone else has any insight on this. I feel like the issue should be correctable as it seems to stem from writeHead() being fired too early. I suspect it may be something a race condition with the routing. Has anyone, stumbling into this thread, figured out a way to get through this issue?

  5. #5
    SitePoint Member
    Join Date
    Apr 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the same issue - if anyone has a tip on how to solve that would be great. I'm also on Maverick's.

  6. #6
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by qosmy View Post
    I have the same issue - if anyone has a tip on how to solve that would be great. I'm also on Maverick's.
    Hello qosmy,

    I did manage to get a working version up and running. You can take a look at the result here: nockmarket It's been a little while since I worked on this now but if I recall I had to upgrade a few packages to get it all working. You should see the dependencies listed in the package.json.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •