node.js - Babel 和 Bluebird promise

标签 node.js bluebird babeljs

默认情况下,Babel 会提供 Promise polyfill。我如何强制它使用 Bluebird 实现或禁用 polyfill(我使用预设 es2015)。

很容易忘记导入 Bluebird 并意外使用 polyfill 实现。

最佳答案

我想这个预设应该可以解决这个问题: babel-preset-async-to-bluebird

正常安装后:

$ npm install --save-dev babel-preset-async-to-bluebird

以下使用 Node API 的代码将启用该预设:

require("babel-core").transform("code", {
  presets: ["async-to-bluebird"]
});

稍微改编自 eknkc 编写的 readme.md

关于node.js - Babel 和 Bluebird promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33948504/

相关文章:

Javascript/NodeJS 回调函数和循环

node.js - 如何在 Jest 中使用 babel-preset-env

javascript - 语法错误: Unexpected token import error

javascript - 未捕获( promise )TypeError : undefined is not a function (Vue. js,Electron)

node.js - Mongoose "update"不起作用,除非我使用 ".then"

javascript - 有谁知道如何使用cheerio(node.js)获取这个特定值?

node.js - 为什么此错误导致应用崩溃,而不是被捕获和处理

javascript - 将 promise 转换为 Bluebird

javascript - Sequelize promise 和正常 node.js 回调的问题

javascript - 将 Babel 添加到 HTML