ES7异步等待功能与巴贝尔装载机不工作

ES7异步等待功能与巴贝尔装载机不工作

本文介绍了ES7异步等待功能与巴贝尔装载机不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行的异步使用的WebPack的通天装载机在JavaScript中等待功能。我使用了以下配置:

  {
  名称:'客户',
  背景:path.join(__目录名称,'src'中,'静','脚本'),
  项:{
    索引:./index.js
  },
  输出:{
    路径:path.join(__目录名称,'src'中,'静','捆绑'),
    文件名:[名] .js文件'
  },
  模块:{
    装载机:
      {
        测试:/\\.js$/,
        装载机:巴别塔,
        查询:{
          $ P $的pset:ES2015,阶段0]
        }
      }
    ]
  },
  解析:{
    根:path.join(__目录名)
    回退:path.join(__目录名称,node_modules'),
    modulesDirectories:['node_modules'],
  }
}

但它一直力推的错误以下消息:

My index.js has this content:

console.log('hi from app');

async function hello() {
  return Promise.resolve('hi')
}

async function conversation () {
  const hi = await hello()
  console.log(hi);
}
解决方案

It looks like you hit a bug. It seems to be solved but not released yet.

If you cannot wait until it is released, you can apply the patch corresponding to the commit that solves the issue.

One way to apply the patch:

Save the following diff into a file (visit.patch for example) in your package root folder. Then apply the patch with git apply visit.patch.


From 940b86dadbd0151c33c02e89f0b5ff61077c9214 Mon Sep 17 00:00:00 2001
From: Henry Zhu <[email protected]>
Date: Thu, 5 Nov 2015 20:10:15 -0500
Subject: [PATCH] transform-regenerator: set node.id to an identifier if null -
 fixes #2835

---
 packages/babel-plugin-transform-regenerator/lib/visit.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/node_modules/babel-preset-es2015/node_modules/babel-plugin-transform-regenerator/lib/visit.js b/node_modules/babel-preset-es2015/node_modules/babel-plugin-transform-regenerator/lib/visit.js
index 0f68ffc..c4a0d2e 100644
--- a/node_modules/babel-preset-es2015/node_modules/babel-plugin-transform-regenerator/lib/visit.js
+++ b/node_modules/babel-preset-es2015/node_modules/babel-plugin-transform-regenerator/lib/visit.js
@@ -146,6 +146,10 @@ function getOuterFnExpr(funPath) {
   var node = funPath.node;
   t.assertFunction(node);

+  if (!node.id) {
+    node.id = funPath.scope.parent.generateUidIdentifier("callee");
+  }
+
   if (node.generator && // Non-generator functions don't need to be marked.
       t.isFunctionDeclaration(node)) {
     var pp = funPath.findParent(function (path) {
@@ -171,9 +175,7 @@ function getOuterFnExpr(funPath) {
     );
   }

-  return node.id || (
-    node.id = funPath.scope.parent.generateUidIdentifier("callee")
-  );
+  return node.id;
 }

 function getRuntimeMarkDecl(blockPath) {


Update:

It seems that the bug wasn't properly fixed and the commit has been reverted. Looks like it was due to another problem that has been addressed in this pull request.

这篇关于ES7异步等待功能与巴贝尔装载机不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:16