peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

ReferenceError: Promise is not defined with node version v0.10.25 #80

Closed wongni closed 8 years ago

wongni commented 8 years ago

I have installed the latest node-hue-api (node-hue-api@2.1.1 extraneous) and created index.js from the example. If I execute the index.js, I get a ReferenceError: Promise is not defined. My node version is v0.10.25 and my OS is Ubuntu-14.04-i386.

Here is the stack trace.

/home/wkkim/workspace/test/node_modules/node-hue-api/node_modules/axios/lib/axios.js:45 var promise = Promise.resolve(config); ^ ReferenceError: Promise is not defined at Axios.request (/home/wkkim/workspace/test/node_modules/node-hue-api/node_modules/axios/lib/axios.js:45:17) at wrap (/home/wkkim/workspace/test/node_modules/node-hue-api/node_modules/axios/lib/helpers/bind.js:9:15) at Object.module.exports.invoke (/home/wkkim/workspace/test/node_modules/node-hue-api/hue-api/httpPromise.js:126:23) at Object.module.exports.locateBridges as nupnpSearch at Object. (/home/wkkim/workspace/test/index.js:9:5) 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 Function.Module.runMain (module.js:497:10)

TwanoO67 commented 8 years ago

Promise are defined by ES6, which isn't supported by node 0.10. You should upgrade to a newer version like the 5.X branch (maybe using "node version manager" to try first)

peter-murray commented 8 years ago

@TwanoO67 is correct, there are no promises in Node.js 0.10 or 0.12.

The axios library that was used to replace the request library (in versions > 1.2.1) requires that promises are present inside the runtime.

It is possible to polyfill the missing promise using the details here; https://github.com/mzabriskie/axios/blob/master/UPGRADE_GUIDE.md#es6-promise-polyfill

If you don't want to polyfill and have another dependency, version 1.2.1 of node-hue-api is the last version that I built that supported Node.js 0.10 and 0.12 without this polyfill. You can install that version using npm install node-hue-api@1.2.1, and it will only be missing a few improvements.

If there is enough of a demand, I could look to release another updated version that has backwards compatibility for Node.js 0.10 and 0.12, Node.js version 4 and 5 have been out for a while now.