javascript – SyntaxError:意外的令牌功能 – 异步等待Nodejs

前端之家收集整理的这篇文章主要介绍了javascript – SyntaxError:意外的令牌功能 – 异步等待Nodejs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用节点版本6.2.1与我的一些代码.已经计划将大多数超级回调代码迁移到看起来更干净,可能性能更好的内容.

我不知道为什么,当我尝试执行节点代码时,终端会抛出一个错误.

helloz.js

  1. (async function testingAsyncAwait() {
  2. await console.log("For Trump's Sake Print me!");
  3. })();

日志 –

  1. BOZZMOB-M-T0HZ:rest bozzmob$node helloz.js
  2. /Users/bozzmob/Documents/work/nextgennms/rest/helloz.js:1
  3. (function (exports,require,module,__filename,__dirname) { (async function testingAsyncAwait() {
  4. ^^^^^^^^
  5. SyntaxError: Unexpected token function
  6. at Object.exports.runInThisContext (vm.js:53:16)
  7. at Module._compile (module.js:513:28)
  8. at Object.Module._extensions..js (module.js:550:10)
  9. at Module.load (module.js:458:32)
  10. at tryModuleLoad (module.js:417:12)
  11. at Function.Module._load (module.js:409:3)
  12. at Function.Module.runMain (module.js:575:10)
  13. at startup (node.js:160:18)
  14. at node.js:456:3
  15. BOZZMOB-M-T0HZ:rest bozzmob$node -v
  16. v6.2.1

我失踪了什么请给我一些灯光.

更新1:

我尝试使用Babel作为Quentin建议,但是,我仍然收到以下错误.

更新代码

要求(“巴别核/注册”);
要求( “巴别-填充工具”);

  1. (async function testingAsyncAwait() {
  2. await console.log("For Trump's Sake Print me!");
  3. })();

日志 –

  1. BOZZMOB-M-T0HZ:rest bozzmob$babel helloz.js > helloz.trans.js
  2. SyntaxError: helloz.js: Unexpected token (3:7)
  3. 1 | require("babel-polyfill");
  4. 2 |
  5. > 3 | (async function testingAsyncAwait() {
  6. | ^
  7. 4 | await console.log("For Trump's Sake Print me!");
  8. 5 | })();

解决方法

异步功能not currently supported by Node.

您需要将代码(例如使用Babel)转换为Node了解的JS版本.

猜你在找的JavaScript相关文章