【问题标题】:gulp-babel plugin doesn't workgulp-babel 插件不起作用
【发布时间】:2015-11-13 15:09:38
【问题描述】:

我尝试将 babel 与 gulp 一起使用。但我遇到了无法解决的错误。

我的 gulp 任务看起来像 `

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    babel = require("gulp-babel");

gulp.task('default', function() {

    gulp.src(cssSrc)
        .pipe(concat('main.css'))
        .pipe(gulp.dest('build'));

    gulp.src(jsSrc)
        .pipe(babel())
        .pipe(concat('app.js'))
        .pipe(gulp.dest('build'));

    gulp.watch(cssSrc,['css-task']);
    gulp.watch(jsSrc,['js-task']);

});

`

jsSrc - js 文件的路径数组

.babelrc 看起来如此

{
"presets": ["es2015"]
}

当我运行 gulp 时,我看到了这个错误

events.js:141
      throw er; // Unhandled 'error' event
      ^
ReferenceError: [BABEL] C:\workspace\projects\test\test-client\app.js: Unknown option: C:\workspace\projects\test\test-client\.babelrc.presets
    at Logger.error (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\logger.js:58:11)
    at OptionManager.mergeOptions (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\options\option-manager.js:126:29)
    at OptionManager.addConfig (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\options\option-manager.js:107:10)
    at OptionManager.findConfigs (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\options\option-manager.js:168:35)
    at OptionManager.init (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\options\option-manager.js:229:12)
    at File.initOptions (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\index.js:147:75)
    at new File (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\index.js:137:22)
    at Pipeline.transform (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\pipeline.js:164:16)
    at DestroyableTransform._transform (C:\workspace\projects\test\test-client\node_modules\gulp-babel\index.js:30:20)
    at DestroyableTransform.Transform._read (C:\workspace\projects\test\test-client\node_modules\gulp-babel\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:10)

app.js- jsSrc 数组中的第一个文件

可能出了什么问题?

【问题讨论】:

  • {"presets": ["es2015"]} 中删除 "presets": ["es2015"] 并将 {} 留在 .babelrc 中,仍然可以编译。

标签: gulp babeljs


【解决方案1】:

我遇到了和你描述的一样的问题。

在我的情况下,解决方案是除了更新模块babel-cli 之外,还将模块gulp-babel 更新到带有npm install gulp-babel --save-dev 的最新版本,因为它们将核心库updated 更新到6.0.*。

希望有帮助!

【讨论】:

  • 是的,将 gulp-babel 更新到版本 6,解决我的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-17
  • 1970-01-01
相关资源
最近更新 更多