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 #73

Closed mwittig closed 8 years ago

mwittig commented 8 years ago

I am trying to run the discovery example included in the README and get the following error.

C:\Users\marcus\Documents\Devel>node --version
v0.10.38

C:\Users\marcus\Documents\Devel>npm -version
2.11.0

C:\Users\marcus\Documents\Devel>npm install node-hue-api --save
npm WARN unmet dependency C:\Users\marcus\Documents\Devel\node_modules\pimatic\node_modules\convict requires cjson@'0.3.0' but will load
npm WARN unmet dependency C:\Users\marcus\Documents\Devel\node_modules\pimatic\node_modules\cjson,
npm WARN unmet dependency which is version 0.3.1
npm WARN unmet dependency C:\Users\marcus\Documents\Devel\node_modules\pimatic\node_modules\express\node_modules\connect requires connect-timeout@'~1.6.2' but will load
npm WARN unmet dependency C:\Users\marcus\Documents\Devel\node_modules\pimatic\node_modules\connect-timeout,
npm WARN unmet dependency which is version 1.7.0
node-hue-api@2.0.0 node_modules\node-hue-api
├── traits@0.4.0
├── deep-extend@0.4.0
├── q@1.4.1
├── xml2js@0.4.15 (sax@1.1.4, xmlbuilder@4.2.0)
└── axios@0.8.1 (follow-redirects@0.0.7)

C:\Users\marcus\Documents\Devel>node tools\hueDiscovery.js

C:\Users\marcus\Documents\Devel\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 (C:\Users\marcus\Documents\Devel\node_modules\node-hue-api\node_modules\axios\lib\axios.js:45:17)
    at wrap (C:\Users\marcus\Documents\Devel\node_modules\node-hue-api\node_modules\axios\lib\helpers\bind.js:9:15)
    at Object.module.exports.invoke (C:\Users\marcus\Documents\Devel\node_modules\node-hue-api\hue-api\httpPromise.js:126:23)
    at Object.module.exports.locateBridges [as nupnpSearch] (C:\Users\marcus\Documents\Devel\node_modules\node-hue-api\hue-api\bridge-discovery.js:31:24)
    at Object.<anonymous> (C:\Users\marcus\Documents\Devel\tools\hueDiscovery.js:10: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)
    at startup (node.js:119:16)
    at node.js:935:3
mwittig commented 8 years ago

Ok, I have managed to solve this myself by installing es6-promise and adding the before the first line of the example code:

var Promise = require('es6-promise');

According to other post found this dependency problem seems to occur with node 0.10. May be it is an issue on axios?

peter-murray commented 8 years ago

It is in the version of axis that I am using, it now requires users to polyfill the Promise if your environment is missing it. https://github.com/mzabriskie/axios/blob/master/UPGRADE_GUIDE.md#es6-promise-polyfill

I am getting ready to cut off support for Node.js 0.10 in favour of the 4.x LTS version, so will not solve this one.

mwittig commented 8 years ago

Ok, no problem. At the moment we're still using node 0.10 with the pimatic project, but I'll hope we'll finish off the new release soon which will be ready for node 4.x.