Page MenuHomePhabricator

express/connect version dependency issue in ParserService.js
Closed, DeclinedPublic

Description

Right now package.json specifies a dependency on express 2.5.x, but that version doesn't parse req.body by default, which is needed in ParserService.js:635. Upgrading it to 3.x.x seems to solve the problem:
https://www.mediawiki.org/wiki/Talk:Parsoid#TypeError:_Cannot_read_property_.27oldid.27_of_undefined


Version: unspecified
Severity: normal

Details

Reference
bz52840

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:44 AM
bzimport added a project: Parsoid-Web-API.
bzimport set Reference to bz52840.

Express 3.x.x is a major version change, it probably breaks lots of stuff. I'm running with 2.5.11 on my machine (and I suspect the rest of the developers are, too). Can you provide more details on the problem you're seeing?

This is a traceback of the problem, as reported by an user on IRC:

TypeError: Cannot read property 'oldid' of undefined

at app.post.cb (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/api/ParserService.js:635:28)
at getParserServiceEnv (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/api/ParserService.js:376:4)
at MWParserEnvironment.getParserEnv (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/lib/mediawiki.parser.environment.js:279:3)
at MWParserEnvironment.switchToConfig (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/lib/mediawiki.parser.environment.js:324:3)
at Function.MWParserEnvironment.getParserEnv (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/lib/mediawiki.parser.environment.js:278:6)
at getParserServiceEnv (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/api/ParserService.js:365:22)
at /opt/bitnami/apache2/htdocs/extensions/Parsoid/js/api/ParserService.js:663:2
at callbacks (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/node_modules/express/lib/router/index.js:272:11)
at param (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/node_modules/express/lib/router/index.js:246:11)
at pass (/opt/bitnami/apache2/htdocs/extensions/Parsoid/js/node_modules/express/lib/router/index.js:253:5)

From further debugging (http://pastebin.com/DbBhJdEE), it seemed like the version of express the user had installed didn't provide req.body. Maybe 3.x.x isn't necessary, but 2.5.11 is?

I think the problem is actually with connect (which provides the bodyParser middleware). We're using connect version 1.9.2, but express only requires connect '1.x'. As far as I can tell from https://github.com/senchalabs/connect/blob/master/History.md, the latest stable 1.x version was 1.8.5, and bodyParser was added/extended in connect 2.0.0. I'm guessing that connect 1.9.2 is a "prerelease 2.0" and so contains some connect 2.0.0 features, like bodyParser.

If someone can reproduce this bug, I'd like to see what happens if they edit node_modules/express/package.json to depend on connect 1.9.x instead of 1.x, and then npm install from the node_modules/express directory.

Alternatively, we might suggest that people clone mediawiki/extensions/Parsoid/js/contrib.git instead of using npm install?

Probably the best way to solve this issue is to go ahead and migrate to express 3.0. See https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x and https://github.com/visionmedia/express/wiki/New-features-in-3.x. Anyone want to tackle this?

I just wiped & re-installed my dependencies without encountering this issue. If there is no way to reproduce this I'd suggest closing it as worksforme.

Multiple people seems to have reported the bug @ https://www.mediawiki.org/wiki/Talk:Parsoid .. so we still need to figure out what is breaking for them.

That might well have been a temporary npm dependency issue.

It was most recently reported this morning.

Might be worth checking if people experiencing this issue actually did a clean install (rm -rf node_modules; npm install), or if there are other special circumstances like Windows or node 0.10.

Yeah, agreed. I'm hoping that someone else stumbles across this so we can debug more in depth. In the meantime, I'd like to double-check the version of express/connect we're using in production, since we don't typically exercise this particular API during development. I don't expect to be surprised, but you never know...

Production and local tests are both fine, which is why I suspect temporary npm issues or special circumstances.

Oh, I don't think that production is broken. I'm just curious to know what version of express/connect got installed. I expect to see them identical to the ones in contrib. But you know, sometimes computers surprise you.

FWIW, both production and my local (re)install have express 2.5.11 and connect 1.9.2. Anybody- please make sure you run npm install after a fresh checkout or after deleting node_modules. Please report your system info if the problem persists:

node --version
npm list
operating system

Thanks for checking production, gwicke.

So- anybody still experiencing this in the wild?

imex163 wrote:

I have the same problem.
[root@localhost api]# node --version
v0.8.22
[root@localhost api]# npm list
mediawiki-parsoid@0.0.1 /var/www/html/wiki/extensions/Parsoid/js
├── alea@0.0.9
├─┬ assert@0.4.9
│ └─┬ util@0.4.9
│ └── events.node@0.4.9
├── async@0.2.9
├── colors@0.6.1
├── diff@1.0.5
├── domino@1.0.12
├── entities@0.2.2
├── events@0.5.0
├─┬ express@2.5.11
│ ├─┬ connect@1.9.2
│ │ └── formidable@1.0.14
│ ├── mime@1.2.4
│ ├── mkdirp@0.3.0
│ └── qs@0.4.2
├── lru-cache@1.1.1
├─┬ optimist@0.6.0
│ ├── minimist@0.0.1
│ └── wordwrap@0.0.2
├── path@0.4.9
├── pegjs@0.7.0
├── querystring@0.2.0
└─┬ request@2.27.0

├── aws-sign@0.3.0
├── cookie-jar@0.3.0
├── forever-agent@0.5.0
├─┬ form-data@0.1.0
│ └─┬ combined-stream@0.0.4
│   └── delayed-stream@0.0.5
├─┬ hawk@1.0.0
│ ├── boom@0.4.2
│ ├── cryptiles@0.2.2
│ ├── hoek@0.9.1
│ └── sntp@0.2.4
├─┬ http-signature@0.10.0
│ ├── asn1@0.1.11
│ ├── assert-plus@0.1.2
│ └── ctype@0.5.2
├── json-stringify-safe@5.0.0
├── mime@1.2.11
├── node-uuid@1.4.1
├── oauth-sign@0.3.0
├── qs@0.6.5
└── tunnel-agent@0.3.0

OS: CentOS 6.4
On server:
ERROR in localhost:Sistem:
Page Fetch failure for null
Stack trace: DoesNotExistError: Page Fetch failure for null
worker 2843 died (1), restarting.

  • worker(2876) loading...
  • worker(2876) ready

(In reply to comment #15)

I have the same problem.

Your dependencies look fine to me, so it is not related to the issue discussed in this bug.

On server:
ERROR in localhost:Sistem:
Page Fetch failure for null
Stack trace: DoesNotExistError: Page Fetch failure for null

Parsoid clearly started up ok, but could not fetch the page 'Sistem:' from the API. Check that this page actually exists and that your API url is configured properly in localsettings.js. Try different pages like http://localhost:8000/localhost/Main_Page in case there is a page called 'Main_Page' in your wiki.

Since we have not been able to reproduce this and have additional reports about successful installs (see for example #15) I am going to close this bug as worksforme. If anybody experiences this after a clean install (after deleting node_modules), then please reopen and provide

node --version
npm list
operating system

stuartbman wrote:

I'm still having problems with the above issue:

On server:
/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639

var doc, oldid = req.body.oldid || null;
                         ^

TypeError: Cannot read property 'oldid' of undefined

at app.post.cb (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639:28)
at getParserServiceEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:380:4)
at MWParserEnvironment.getParserEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:279:3)
at setupWikiConfig (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:299:3)
at ApiRequest._processListeners.processSome (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.ApiRequest.js:107:17)
at process.startup.processNextTick.process._tickCallback (node.js:245:9)

worker 3410 died (1), restarting.

node --version v0.825
npm list

  • alea@0.0.9

---¬ assert@0.4.9

  • ---¬ util@0.4.9
  • --- events.node@0.4.9
    • async@0.2.9
    • colors@0.6.0-1
    • diff@1.0.5
    • domino@1.0.12
    • entities@0.2.2
    • events@0.5.0

---¬ express@2.5.0

  • ---¬ connect@1.7.0
  • - --- mime@1.2.11
  • --- mime@1.2.11
  • --- mkdirp@0.0.7
  • --- qs@0.6.5
    • html5-entities@0.5.0
    • lru-cache@1.0.1

---¬ optimist@0.6.0

  • --- minimist@0.0.2
  • --- wordwrap@0.0.2
    • path@0.4.9
    • pegjs@0.7.0
    • querystring@0.2.0

---¬ request@2.27.0

    • aws-sign@0.3.0
    • cookie-jar@0.3.0
    • forever-agent@0.5.0 ---¬ form-data@0.1.1
  • ---¬ combined-stream@0.0.4
  • --- delayed-stream@0.0.5 ---¬ hawk@1.0.0
  • ---¬ boom@0.4.0
  • - --- hoek@0.8.0
  • --- cryptiles@0.2.2
  • --- hoek@0.9.0
  • --- sntp@0.2.4 ---¬ http-signature@0.10.0
  • --- asn1@0.1.11
  • --- assert-plus@0.1.2
  • --- ctype@0.5.2
    • json-stringify-safe@5.0.0
    • mime@1.2.11
    • node-uuid@1.4.1
    • oauth-sign@0.3.0
    • qs@0.6.5
    • tunnel-agent@0.3.0

OS: Ubuntu 12.04.2 LTS

Stu, it seems you have old versions of express and connect, which will produce this error. Can you try to delete Parsoid/js/node_modules and do 'npm install' again, see if the error goes away?

stuartbman wrote:

Thanks Marc,
Still receiving this error after I performed delete then npm install, which yielded the same --version. Force updated express with npm install -f express@3.x
npm list

  • alea@0.0.9

---¬ assert@0.4.9

  • ---¬ util@0.4.9
  • --- events.node@0.4.9
    • async@0.2.9
    • colors@0.6.2
    • diff@1.0.6
    • domino@1.0.12
    • entities@0.2.2
    • events@0.5.0

---¬ express@3.3.8 invalid

  • --- buffer-crc32@0.2.1
  • ---¬ commander@1.2.0
  • - --- keypress@0.1.0
  • ---¬ connect@2.8.8
  • - --- bytes@0.2.0
  • - --- formidable@1.0.14
  • - --- pause@0.0.1
  • - --- qs@0.6.5
  • - --- uid2@0.0.2
  • --- cookie@0.1.0
  • --- cookie-signature@1.0.1
  • --- debug@0.7.2
  • --- fresh@0.2.0
  • --- methods@0.0.1
  • --- mkdirp@0.3.5
  • --- range-parser@0.0.4
  • ---¬ send@0.1.4
  • --- mime@1.2.11
    • html5-entities@0.5.0
    • lru-cache@1.0.1

---¬ optimist@0.6.0

  • --- minimist@0.0.2
  • --- wordwrap@0.0.2
    • path@0.4.9
    • pegjs@0.7.0
    • querystring@0.2.0

---¬ request@2.27.0

    • aws-sign@0.3.0
    • cookie-jar@0.3.0
    • forever-agent@0.5.0 ---¬ form-data@0.1.1
  • ---¬ combined-stream@0.0.4
  • --- delayed-stream@0.0.5 ---¬ hawk@1.0.0
  • ---¬ boom@0.4.0
  • - --- hoek@0.8.0
  • --- cryptiles@0.2.2
  • --- hoek@0.9.0
  • --- sntp@0.2.4 ---¬ http-signature@0.10.0
  • --- asn1@0.1.11
  • --- assert-plus@0.1.2
  • --- ctype@0.5.2
    • json-stringify-safe@5.0.0
    • mime@1.2.11
    • node-uuid@1.4.1
    • oauth-sign@0.3.0
    • qs@0.6.5
    • tunnel-agent@0.3.0

On server:
/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639

var doc, oldid = req.body.oldid || null;
                         ^

TypeError: Cannot read property 'oldid' of undefined

at app.post.cb (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639:28)
at getParserServiceEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:380:4)
at MWParserEnvironment.getParserEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:279:3)
at setupWikiConfig (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:299:3)
at ApiRequest._processListeners.processSome (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.ApiRequest.js:107:17)
at process.startup.processNextTick.process._tickCallback (node.js:245:9)

worker 7538 died (1), restarting.

  • worker(7791) loading...

Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:

var express = require("express");
var app = express();

Thanks for the info. It's strange that npm install doesn't give the same versions as the ones we get in production (express 2.5.11 and connect 1.9.2). Could you try with those, see if the error is still present?

stuartbman wrote:

Hi Marc,
Sadly still going:

npm list:

  • alea@0.0.9

---¬ assert@0.4.9

  • ---¬ util@0.4.9
  • --- events.node@0.4.9
    • async@0.2.9
    • colors@0.6.2

---¬ connect@1.9.2 extraneous

  • --- formidable@1.0.14
  • --- mime@1.2.11
  • --- qs@0.6.5
    • diff@1.0.6
    • domino@1.0.12
    • entities@0.2.2
    • events@0.5.0

---¬ express@2.5.11

  • --- connect@1.0.0
  • --- mime@1.2.4
  • --- mkdirp@0.3.0
  • --- qs@0.4.0
    • html5-entities@0.5.0
    • lru-cache@1.0.1

---¬ optimist@0.6.0

  • --- minimist@0.0.2
  • --- wordwrap@0.0.2
    • path@0.4.9
    • pegjs@0.7.0
    • querystring@0.2.0

---¬ request@2.27.0

    • aws-sign@0.3.0
    • cookie-jar@0.3.0
    • forever-agent@0.5.0 ---¬ form-data@0.1.1
  • ---¬ combined-stream@0.0.4
  • --- delayed-stream@0.0.5 ---¬ hawk@1.0.0
  • ---¬ boom@0.4.0
  • - --- hoek@0.8.0
  • --- cryptiles@0.2.2
  • --- hoek@0.9.0
  • --- sntp@0.2.4 ---¬ http-signature@0.10.0
  • --- asn1@0.1.11
  • --- assert-plus@0.1.2
  • --- ctype@0.5.2
    • json-stringify-safe@5.0.0
    • mime@1.2.11
    • node-uuid@1.4.1
    • oauth-sign@0.3.0
    • qs@0.6.5
    • tunnel-agent@0.3.0

On server:
/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639

var doc, oldid = req.body.oldid || null;
                         ^

TypeError: Cannot read property 'oldid' of undefined

at app.post.cb (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:639:28)
at getParserServiceEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/api/ParserService.js:380:4)
at MWParserEnvironment.getParserEnv (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:279:3)
at setupWikiConfig (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.parser.environment.js:299:3)
at ApiRequest._processListeners.processSome (/var/www/vhosts/website.co.uk/httpdocs/Parsoid/js/lib/mediawiki.ApiRequest.js:107:17)
at process.startup.processNextTick.process._tickCallback (node.js:245:9)

worker 10557 died (1), restarting.

Stu, sorry to keep banging on this, but you seem to have a very old version of connect (1.0.0), we use 1.9.2 in production.

stuartbman wrote:

Thanks very much for your help Marc; I had installed the updated connect in the root folder, rather than under express, it's all working now.