Using async/await in Node 6 with Babel

前端 未结 2 1094
醉话见心
醉话见心 2020-12-08 21:40

I\'m trying to configure Babel for Node v6.9.2. I want to use async/await constructs.

Because I\'m new to Babel and all Node infrastructur

2条回答
  •  旧巷少年郎
    2020-12-08 22:30

    Short answer

    Use Babel preset for Node 6.x:

    • https://www.npmjs.com/package/babel-preset-node6

    Long answer

    To see what ES feature is supported in a given Node version, see:

    • http://node.green/

    For async/await support in particular, see:

    • http://node.green/#ES2017-features-async-functions

    If you use Node v7.x (the current version) then you can use the --harmony flag and use async/await natively without transpilation.

    Node v8.x (available as nightly builds) doesn't even need the --harmony flag for that.

    But note that Node doesn't support import/export - to know why see:

    • javascript - Why is there a spec for sync and async modules?
    • Exporting Node module from promise result

提交回复
热议问题