npm i regenerator-runtime
在小程序中,不认识 node_modules 文件夹,无法通过以下方法来直接找到包文件
import regeneratorRuntime form 'regenerator-runtime'
所以需要将 regenerator-runtime 中的 runtime.js(支持async/await的核心文件) 拿出来存放到一个文件夹中,通过一般的文件引入方式使用。
例:
import regeneratorRuntime from '../../lib/runtime.js'
值得一提的是导出的名字必须为 regeneratorRuntime ,否则无法使用async/await
使用过程中如果出现一些意外,我在构建npm版中有记录到一个碰到的错误
使用async/await(构建npm版): https://cloud.tencent.com/developer/article/1684833
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有