未定义符号错误
I run into this problem in a project using Babel as soon as I added an async
function, but the problem is the same for any recent JavaScript feature:
添加async
功能后,我立即在使用Babel的项目中遇到了这个问题,但是最近的任何JavaScript功能都存在相同的问题:
Babel, used by Parcel, generates a polyfill, but to avoid this error you need to also load the regenerator-runtime
runtime.
Parcel使用的Babel生成一个polyfill,但是要避免此错误,您还需要加载regenerator-runtime
运行时。
One solution: add to the top of your main JavaScript file:
一种解决方案:添加到主JavaScript文件的顶部:
import 'regenerator-runtime/runtime'
Parcel will include this package by default, increasing the size of 25KB.
默认情况下,Parcel将包括此软件包,增加25KB的大小。
The solution that is the most efficient in terms of codebase is adding the browserslist
property to your package.json.
就代码库而言,最有效的解决方案是将browserslist
属性添加到package.json。
For example:
例如:
"browserslist": [
"last 1 Chrome version"
]
For testing is good enough. To support multiple browsers:
对于测试已经足够了。 要支持多种浏览器:
"browserslist": [
"last 3 and_chr versions",
"last 3 chrome versions",
"last 3 opera versions",
"last 3 ios_saf versions",
"last 3 safari versions"
]
or also:
或者:
"browserslist": [
"since 2017-06"
]
You have to add a version that’s recent enough to support async/await
, so Babel does not try to add a polyfill.
您必须添加最新的版本以支持async/await
,因此Babel不会尝试添加polyfill。
Check all the valid values here: https://github.com/browserslist/browserslist
在此处检查所有有效值: https : //github.com/browserslist/browserslist
翻译自: https://flaviocopes.com/parcel-regeneratorruntime-not-defined/
未定义符号错误