我有一个JS项目,我试图使用async/await
,我已经安装了相关的包来转换运行时,但仍然得到这个错误:
未定义regeneratorRuntime
我错过了什么?
package.json
"dependencies": {
"@babel/core": "^7.14.0",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.14.1",
"bootstrap": "4.6.0",
"eslint": "7.21.*",
"gulp": "4.0.2",
"gulp-autoprefixer": "7.0.*",
"gulp-babel": "^8.0.0",
"gulp-concat": "2.6.*",
"gulp-eslint": "6.0.*",
"gulp-minify": "3.1.*",
"gulp-sass": "4.1.*",
"gulp-stylelint": "13.0.*",
"stylelint": "13.11.*"
},
gulpfile.js
const gulp = require('gulp')
const sass = require('gulp-sass')
const babel = require('gulp-babel')
const concat = require('gulp-concat')
const minify = require('gulp-minify')
const eslint = require('gulp-eslint')
const autoprefixer = require('gulp-autoprefixer')
// build the JS
gulp.task('build-js', () =>
gulp.src([
'src/js/plugins/input.js'
])
.pipe(concat('output.js'))
.pipe(babel({
presets: [['@babel/env', { modules: false }]]
}))
.pipe(minify())
.pipe(gulp.dest('src/assets/js/'))
);
1条答案
按热度按时间r55awzrz1#
我也遇到了同样的问题。解决办法是将
output.js
文件与node_modules/regenerator-runtime/runtime.js
文件连接起来。基本上你只需要在你的网站中的某个地方加载这个文件。我没有发现需要
@babel/plugin-transform-runtime
,但我仍然理解这一切是如何工作的,所以让我知道是否有必要。下面是一个可能的
gulpfile.js
: