mozilla/doctorjs — Issue #33: Cannot read property 'type' of undefined
Author: boushley
Created: 2012-01-15 03:42:52+00:00
State: open

I have had a problem running jsctags on underscore.js and backbone.js both of them reporting ```Cannot read property 'type' of undefined```. The entire error looks like the following:
```
Cannot read property 'type' of undefined

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'type' of undefined
at Object. (/usr/local/lib/cfa2/jscfa.js:1168:12)
at Object.recur (/usr/local/lib/cfa2/jscfa.js:578:41)
at /usr/local/lib/cfa2/jscfa.js:588:13
at Array.forEach (native)
at Object._haskids (/usr/local/lib/cfa2/jscfa.js:586:8)
at Object.recur (/usr/local/lib/cfa2/jscfa.js:578:41)
at /usr/local/lib/cfa2/jscfa.js:588:13
at Array.forEach (native)
at Object._haskids (/usr/local/lib/cfa2/jscfa.js:586:8)
at Object.recur (/usr/local/lib/cfa2/jscfa.js:578:41)
```
The error message didn't seem to point me towards the source of the error. However in both of these libraries I was able to track down the source of the error to the following.

In backbone.js:
```javascript
if (typeof exports !== 'undefined') {
```
and
```javascript
if (!_ && (typeof require !== 'undefined')) _ = require('underscore');
```

In underscore.js:
```javascript
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
```

It appears this method of checking if we are in node.js is causing problems.

Any suggested workaround for this?