Taro新建项目使用async报错regeneratorRuntime is not defined

当用 Taro 命令 taro init myApp 创建项目的时候,等程序运行结束,进入到 myApp 目录中,执行 npm run dev:weapp 的时候,代码可以正常运行。

但是当我们在代码中用 async/await 的方式写了一些代码之后,就不能正常运行了,报错如下:

VM49:1 thirdScriptError
regeneratorRuntime is not defined
ReferenceError: regeneratorRuntime is not defined

原因就是缺少安装 babel-plugin-transform-runtime 和 babel-runtime 两个依赖。

yarn add babel-plugin-transform-runtime --dev
yarn add babel-runtime

??注意:如果是 Taro v1 版本的话,还需要安装 @tarojs/async-await 这个包。升级到 Taro v2 版本后就不需要这个包了。

安装完成之后,需要修改一下 config/index.js 文件:

plugins: [
    ‘transform-decorators-legacy‘,
    ‘transform-class-properties‘,
    ‘transform-object-rest-spread‘,
+   [‘transform-runtime‘, {
+       "helpers": false,
+       "polyfill": false,
+       "regenerator": true,
+       "moduleName": ‘babel-runtime‘
+   }]
}

其中前面带有 + 部分是需要添加的内容。

另外,当我们在 Taro中使用 async 的方式写代码时,还需要在开发前配置这些地方请添加链接描述

再次运行,小程序就不会报错啦!

我的博客:https://www.wanghuiblog.com

原文地址:https://blog.51cto.com/6638574/2464092

时间: 2024-07-30 23:01:48

Taro新建项目使用async报错regeneratorRuntime is not defined的相关文章

导入项目的时候报错Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha7

问题描述 今天在导入项目的时候报错: Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha7. 原因是:没有下载相应版本的ConstraintLayout. 解决方案 工具栏上选择 Tools --> Android -->SDK Manager 切换到SDK Tools选项,在右下角处勾选 Show Package Details 在Support Repository下的Const

maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

本篇文章主要介绍了"maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener ",主要涉及到maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 方面的内容,对于maven web 项目中启动报错jav

【IDEA】创建maven项目时,报错[FATAL_ERROR] Cannot start Maven: Cannot find JRE '1.7'

在使用IDEA使用maven创建springMVC项目时,出现下面的错误,导致无法创建生成正常的springMVC项目结构,而只有一个pom文件: [FATAL_ERROR] Cannot start Maven: Cannot find JRE '1.7' 原因是:我在默认的setting配置里,File-->Other Setting-->Default Setting对应的maven配置里,设置了runner的VM参数:-DarchetypeCatalog=internal,这里需要用到

ASP.NET MVC 复制MVC项目代码到同一个项目的时候报错The request for ‘home’ has found the following matching controll

ASP.NET MVC 复制MVC项目代码到同一个项目的时候报错The request for 'home' has found the following matching controll "/"应用程序中的服务器错误. Multiple types were found that match the controller named 'home'. This can happen if the route that services this request ('{control

vue项目报错webpackJsonp is not defined

在vue单页面应用中,我们大概都会使用CommonsChunkPlugin这个插件. 传送门 CommonsChunkPlugin 但是在项目经过本地测试没有任何问题,打包上线后却会报错 webpackJsonp is not defined.这是因为公共文件必须在自己引用的js文件之前引用. 可以手动改文件引用,但是推荐以下解决办法: 找到build→webpack.prod.conf.js→找到HtmlWebpackPlugin插件,添加如下配置即可 chunks: ['manifest',

启动项目,编译报错:Consider defining a bean of type 'XXX' in your configuration.

在controller层注入ConfigBean,编译器报错: 一开是以为是intellij idea 的告警级别设定的问题,就没有在意,继续启动项目,结果控制台报错:Consider defining a bean of type 'XXX' in your configuration. 错误信息显示找不到这个Bean类. 但是我明明写了啊. 后来经过一番查找,大概有了如下理解:主要问题出在@SpringBootApplication 这个注解上. 点进这个注解,可以看到,此注解功能大概由下面

Spring Boot 2.1.7 启动项目失败,报错: "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."

一开始按照网上的很多解决办法是: 启动类头部声明@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),但是这样会排除掉我自己的数据库配置, 检查了很多地方都没发现问题在哪里,最后自己猜想不论怎么修改application.yml文件,都不生效,是不是因为这个配置文件就没有被加载到? 带着这个想法我就去网上搜了一下问题,有个问题看到了target目录的作用,就去想了一下是不是application.yml文件没有被

【maven】Maven插件篇 --- maven项目 mvn install 报错: Failed to execute goal on project 项目名: Could not resolve dependencies for project

参考:Maven实用技巧 https://msd.misuland.com/pd/3255817963235707346 报错: maven项目 mvn install 报错: [ERROR] Failed to execute goal on project 项目名XXX: Could not resolve dependencies for project com.项目名XXX:war:1.0.0-SNAPSHOT: Failure to find 项目名1XXX:jar:0.1.0-SNA

关于新建android项目时 appcompat_v7报错问题的一点总结

说下我的解决方案: 1.确保 appcompat项目的 target版本 低于 实际项目的android版本 2.确保 appcompat的项目编码与eclipse工具的编码一致,我就是犯了这个错误,导致引用appcompat总是失败... 我的eclipse环境是utf-8编码, 但是 appcompat项目 新建的时候默认是 gbk编码,右键appcompat项目>>属性>>Resource>>把编码改成utf-8即可 3.确保 你的项目和appcompat类库 在