Неожиданное ключевое слово «function», ожидаемый punc «,» - PullRequest
0 голосов
/ 21 ноября 2018

Вот сообщение об ошибке после того, как я пытаюсь запустить свое приложение

[15:32:01] Запуск 'default' ...

[15:32:01] Водопроводчик обнаружил необработанную ошибку:

GulpUglifyError: невозможно минимизировать JavaScript

Причина: SyntaxError: Неожиданное ключевое слово токена «function», ожидаемый punc «,»

Файл: /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/**/*']))

Если я правильно понимаю проблему, мой код должен бытьперенесено в es5 с помощью babel, так что вот .babelrc

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

Вот код из строки 81 (где начинаются комментарии) из myfile.js .

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"
  },
...