Why would I get a “Promise is not defined.” error on Node v5.7.0

淺唱寂寞╮ 提交于 2019-12-03 11:24:08

I cant answer why this is happening, but after reinstalling all npm packages, I still had the same error, so I used this very old solution to "monkeypatch" Promises into node:

npm install es6-promise

and then add the code:

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

And that "solved" the problem.

Edit (a year later): people are still up-voting this answer so I just want to point out to anyone encountering this, the question has gotten a ton of views and seems to be a common issue considering how weird it is - a deduction I later made was that the only reasonable explanation is that one of my libraries (perhaps many libraries do this same thing) built before promises were introduce, had them implemented manually and caused a conflict when Node was updated to support promises officially.

You might be running a legacy version of a maintained library for whatever reason (sometimes necessary to avoid maintenance of your older servers) or be running a current version of an old library that's no longer maintained. Either way, this solution seems to work.

Upgrading node to latest version(v4.5.0) did resolved this issue.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!