Node-bunyan: "ReferenceError: Set is not defined" in older versions of node

Created on 3 Mar 2017  ·  9Comments  ·  Source: trentm/node-bunyan

It looks like the latest 1.8.6 release is throwing errors in older versions of node/V8 that do not support the Set object.

➜  bunyan node test.js 

/Users/justinmcconnell/Documents/code/bunyan/node_modules/bunyan/lib/bunyan.js:1200
var safeCycles = Set ? safeCyclesSet : safeCyclesArray;
                 ^
ReferenceError: Set is not defined
    at Object.<anonymous> (/Users/justinmcconnell/Documents/code/bunyan/node_modules/bunyan/lib/bunyan.js:1200:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/justinmcconnell/Documents/code/bunyan/test.js:3:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

I believe this could be simply solved by changing line 1200 to:
var safeCycles = typeof Set !== 'undefined' ? safeCyclesSet : safeCyclesArray;

My node version:

➜  bunyan node -v
v0.10.37

package.json:

{
  "dependencies": {
    "bunyan": "1.8.5"
  }
}

test.js:

'use strict';

var bunyan = require('bunyan');
console.log('required');

All 9 comments

I submitted this PR.

[email protected] published with this fix. @JustinMcConnell Thanks!

Hey Trent. Thanks for the quick turnaround! ❤️ open source.

Interesting, it's still broken when I get the module from npm.
Here is the line from the PR:
var safeCycles = typeof Set !== 'undefined' ? safeCyclesSet : safeCyclesArray;

Here's the line as it shows in the master branch:
var safeCycles = typeof (Set !== 'undefined') ? safeCyclesSet : safeCyclesArray;

Somehow it got modified.

Yah, I screwed up. Fixed and published as [email protected]. Sorry about that.

using 1.8.8

var safeCycles = typeof (Set) !== 'undefined' ? safeCyclesSet : safeCyclesArray;

ReferenceError: Set is not defined

at Object.<anonymous> (...../node_modules/bunyan/lib/bunyan.js line: 1200 column: 26)

@cyrfer Really? Here is what I see:

$ node
> process.version
'v0.10.48'
> typeof (Set)
'undefined'

Works for me in 0.10.37

$ node
> process.version
'v0.10.37'
> typeof (Set)
'undefined'

I retract my statement. I'm not sure how I got that error. After another install I see it working in 0.10.26.

Was this page helpful?
0 / 5 - 0 ratings