danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 192 forks source link

req.setHeader(...).setHeader is not a function in iconv example #159

Closed ghost closed 8 years ago

ghost commented 8 years ago

node 5.4.0, npm 3.5.2, node-feedparser 1.4.4

I ran the SIMPLE example, and got the README example working well with a BBC News feed.

The Readme says:

"I strongly encourage you to take a look at the iconv example for a very thorough working example."

OK, so after npm install request iconv I'm now getting this error:

/home/me/node_modules/feedparser/examples/iconv.js:18
     .setHeader('accept', 'text/html,application/xhtml+xml');
      ^

TypeError: req.setHeader(...).setHeader is not a function
    at fetch (/home/me/node_modules/feedparser/examples/iconv.js:18:7)
    at Server.<anonymous> (/home/me/node_modules/feedparser/examples/iconv.js:88:3)
    at Server.g (events.js:261:16)
    at emitNone (events.js:68:13)
    at Server.emit (events.js:167:7)
    at emitListeningNT (net.js:1264:10)
    at nextTickCallbackWith1Arg (node.js:444:9)
    at process._tickCallback (node.js:366:17)
    at Function.Module.runMain (module.js:433:11)
    at startup (node.js:141:18)

I'll throw my hands up and admit to being a node noob, but previously packages have just worked.

I realise the problem may lie elsewhere and I feel like I'm being really thick here, but any pointers would be appreciated. Here's my node packages tree. Thanks.

├─┬ feedparser@1.1.4
│ ├── addressparser@0.1.3
│ ├── array-indexofobject@0.0.1
│ ├─┬ readable-stream@1.0.33
│ │ ├── core-util-is@1.0.2
│ │ ├── inherits@2.0.1
│ │ ├── isarray@0.0.1
│ │ └── string_decoder@0.10.31
│ └── sax@0.6.1
├─┬ iconv@2.1.11
│ └── nan@2.0.9
└─┬ request@2.67.0
  ├── aws-sign2@0.6.0
  ├─┬ bl@1.0.0
  │ └─┬ readable-stream@2.0.5
  │   ├── process-nextick-args@1.0.6
  │   └── util-deprecate@1.0.2
  ├── caseless@0.11.0
  ├─┬ combined-stream@1.0.5
  │ └── delayed-stream@1.0.0
  ├── extend@3.0.0
  ├── forever-agent@0.6.1
  ├─┬ form-data@1.0.0-rc3
  │ └── async@1.5.2
  ├─┬ har-validator@2.0.3
  │ ├─┬ chalk@1.1.1
  │ │ ├── ansi-styles@2.1.0
  │ │ ├── escape-string-regexp@1.0.4
  │ │ ├─┬ has-ansi@2.0.0
  │ │ │ └── ansi-regex@2.0.0
  │ │ ├── strip-ansi@3.0.0
  │ │ └── supports-color@2.0.0
  │ ├─┬ commander@2.9.0
  │ │ └── graceful-readlink@1.0.1
  │ ├─┬ is-my-json-valid@2.12.3
  │ │ ├── generate-function@2.0.0
  │ │ ├─┬ generate-object-property@1.2.0
  │ │ │ └── is-property@1.0.2
  │ │ ├── jsonpointer@2.0.0
  │ │ └── xtend@4.0.1
  │ └─┬ pinkie-promise@2.0.0
  │   └── pinkie@2.0.1
  ├─┬ hawk@3.1.2
  │ ├── boom@2.10.1
  │ ├── cryptiles@2.0.5
  │ ├── hoek@2.16.3
  │ └── sntp@1.0.9
  ├─┬ http-signature@1.1.0
  │ ├── assert-plus@0.1.5
  │ ├─┬ jsprim@1.2.2
  │ │ ├── extsprintf@1.0.2
  │ │ ├── json-schema@0.2.2
  │ │ └── verror@1.3.6
  │ └─┬ sshpk@1.7.2
  │   ├── asn1@0.2.3
  │   ├── assert-plus@0.2.0
  │   ├── dashdash@1.11.0
  │   ├── ecc-jsbn@0.1.1
  │   ├── jodid25519@1.0.2
  │   ├── jsbn@0.1.0
  │   └── tweetnacl@0.13.3
  ├── is-typedarray@1.0.0
  ├── isstream@0.1.2
  ├── json-stringify-safe@5.0.1
  ├─┬ mime-types@2.1.9
  │ └── mime-db@1.21.0
  ├── node-uuid@1.4.7
  ├── oauth-sign@0.8.0
  ├── qs@5.2.0
  ├── stringstream@0.0.5
  ├── tough-cookie@2.2.1
  └── tunnel-agent@0.4.2
danmactough commented 8 years ago

@lardconcepts It looks like somewhere along the way, the request module made a breaking change. This project specifies request v2.27.x, for which the example works, however.

ghost commented 8 years ago

Ah... when I installed from npm, I had to get the inconv and request packages manually as it didn't seem to install them. Should it have? Not sure what went wrong there. Thanks for spotting that - shall I log it as a ticket about the latest request breaking it?

danmactough commented 8 years ago

when I installed from npm, I had to get the inconv and request packages manually as it didn't seem to install them. Should it have?

If you cloned feedparser and ran npm install in the feedparser directory, it should have installed iconv and request (and mocha) -- all the devDependencies in the package.json.

Digging through the git history of request, it looks like they broke this a loooooong time ago - in the 2.40.x to 2.41.x changeset, over a year ago. Specifically, this commit.

Not sure it's worth pointing out at this point, to be honest.

danmactough commented 8 years ago

@lardconcepts I updated the examples to avoid future travelers falling into the same trap. Thanks for opening the issue.