2016-08-28 74 views
1

我在我的gulp構建腳本中有gulp-babel任務,並且它運行良好,直到我刪除了node_modules目錄並再次運行npm install。 它返回gulp-babel在刪除node_modules後得到語法錯誤並再次運行npm install

SyntaxError: j.js: Unexpected token (790:10) 

和錯誤日誌指出錯誤標記爲:

789 |  data, 
> 790 |  async = true, 
     |   ^
    791 |  cache = 'no-cache', 
    792 |  method = 'GET', 
    793 |  headers = {}, 

如果我編譯j.js直接CLI babel j.js,不會得到錯誤信息,並返回編譯後的代碼如預期。

我一飲而盡任務代碼:

const gulp = require('gulp'); 
const { babel } = require('gulp-load-plugins')(); 

gulp.task('babel',() => { 
    return gulp.src([ 
     '.tmp/j.js' 
    ]).pipe(babel()).pipe(gulp.dest('.tmp')); 
}); 

我.babelrc:

{ 
    "presets" : [ "es2016" ], 
    "plugins" : [ 
     "transform-es2015-arrow-functions", 
     "transform-es2015-object-super", 
     "transform-es2015-parameters", 
     "transform-object-assign", 
     "transform-es2015-block-scoping", 
     "transform-es2015-shorthand-properties", 
     "transform-es2015-block-scoped-functions", 
     "transform-es2015-for-of", 
     "transform-es2015-destructuring", 
     [ "transform-es2015-classes", { "loose" : true } ], 
     [ "transform-es2015-spread", { "loose" : true } ], 
     [ "transform-es2015-template-literals", { "loose" : true } ] 
    ] 
} 

我NPM的依賴關係:

"devDependencies": { 
    "babel-cli": "^6.14.0", 
    "gulp-babel": "^6.1.2", 
    "babel-plugin-transform-es2015-arrow-functions": "^6.8.0", 
    "babel-plugin-transform-es2015-block-scoped-functions": "^6.8.0", 
    "babel-plugin-transform-es2015-block-scoping": "^6.10.1", 
    "babel-plugin-transform-es2015-classes": "^6.9.0", 
    "babel-plugin-transform-es2015-destructuring": "^6.9.0", 
    "babel-plugin-transform-es2015-for-of": "^6.8.0", 
    "babel-plugin-transform-es2015-object-super": "^6.8.0", 
    "babel-plugin-transform-es2015-parameters": "^6.11.4", 
    "babel-plugin-transform-es2015-shorthand-properties": "^6.8.0", 
    "babel-plugin-transform-es2015-spread": "^6.8.0", 
    "babel-plugin-transform-es2015-template-literals": "^6.8.0", 
    "babel-plugin-transform-object-assign": "^6.8.0", 
    "babel-preset-es2016": "^6.11.3", 
    "colors": "^1.1.2", 
    "del": "^2.2.2", 
    "gulp": "^3.9.1", 
    "gulp-concat": "^2.6.0", 
    "gulp-file-include": "^0.14.0", 
    "gulp-load-plugins": "^1.2.4", 
    "gulp-uglify": "^2.0.0", 
    "gulp-watch": "^4.3.9", 
    "require-dir": "^0.3.0", 
    "run-sequence": "^1.2.2", 
    "uglify-js": "github:mishoo/UglifyJS2#harmony" 
    }, 

回答

0

我來了再回答我的問題。

Babeljs 6.14.0開始支持在ES7中聲明的「異步函數」。單詞「async」成爲編譯器的關鍵字,所以我不能使用「async」作爲變量名稱。

然後我改變「async = true」爲「sync = false」來解決這個問題。

我向github上的Babeljs報告了一個問題。我認爲這個問題已經解決了。

相關問題