意外的标记关键字“功能”,预期的时间点«,»

时间:2018-11-21 14:53:25

标签: gulp babeljs

这是我尝试运行我的应用程序后出现的错误消息

  

[15:32:01]开始“默认” ...

     

[15:32:01]水管工发现未处理的错误:

     

GulpUglifyError:无法缩小JavaScript

     

起因:语法错误:预期的标记关键字“功能”异常   点«,»

     

文件:/home/*******/myfile.js行:81

我的gulp文件:

const gulp = require('gulp')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const plumber = require('gulp-plumber')
const del = require('del')

gulp.task('default', ['conf'], () => gulp.src('src/app/**/*.js')
  .pipe(plumber())
  .pipe(babel())
  .pipe(uglify())
  .pipe(gulp.dest('dist')))

gulp.task('conf', ['package'], () => gulp.src('./src/conf/*').pipe(gulp.dest('dist/conf')))

gulp.task('package', ['clean'], () => gulp.src(['./package.json']).pipe(gulp.dest('dist/')))

gulp.task('clean', () => del(['dist/**/*']))

如果我正确理解了这个问题,我的代码必须由babel编译到es5,所以这里是 .babelrc

{
  "plugins": [
    "transform-class-properties", 
    "babel-plugin-transform-runtime",
    "transform-es2015-shorthand-properties",
    ["babel-plugin-root-import", {
      "rootPathSuffix": "src/app"
    }]
  ],
  "presets": ["es2015"]
}

这是 myfile.js 中第81行(注释开始的地方)的代码。

export default class Scraper {
  // ...
  /**
   * Converts a html string to a cheerio object
   * @param {String} html The html string
   * @return {Object} The cheerio object
   */
  htmlToDom(html) {
    // https://bugs.chromium.org/p/v8/issues/detail?id=2869
    // https://github.com/cheeriojs/cheerio/issues/263
    if(typeof global.gc === 'function') {
      global.gc()
      html = (' ' + html).substr(1)
    }
    return cheerio.load(html)
  }

  static absolute(location, relative) {
  //...
}

首先,我认为可能是造成问题的简化版本,但是我安装了transform-es2015-shorthand-properties,在较旧的项目中,我使用了完全相同的框架,但没有此插件。

更新

  "dependencies": {
    "babel-plugin-transform-class-properties": "^6.24.1",
    "bunyan": "^1.8.10",
    "cheerio": "^1.0.0-rc.2",
    "colors": "^1.1.2",
    "js-yaml": "^3.12.0",
    "pg": "^7.4.3",
    "puppeteer": "^1.5.0",
    "sequelize": "^4.38.0",
    "sequelize-connect": "^2.1.1"
  },
  "devDependencies": {
    "ava": "^0.19.1",
    "babel-plugin-root-import": "^6.1.0",
    "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-latest": "^6.24.1",
    "babel-register": "^6.24.1",
    "coveralls": "^2.13.0",
    "del": "^2.2.2",
    "esdoc": "^0.5.2",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2",
    "gulp-plumber": "^1.1.0",
    "gulp-uglify": "^2.1.2",
    "mkdir-recursive": "^0.4.0",
    "nyc": "^11.2.0",
    "sinon": "^2.1.0",
    "standard": "^10.0.1",
    "wait-on": "^3.2.0"
  },

0 个答案:

没有答案