Gulp 意外的标记关键字function,应为punc,

enyaitl3  于 2022-12-08  发布在  Gulp
关注(0)|答案(2)|浏览(168)

以下是我尝试运行应用程序后的错误消息
[15:32:01]正在启动“默认设置...”
[15:32:01]管道工发现未处理的错误:
GulpUglify错误:无法缩小JavaScript
原因:语法错误:意外的标记关键字function,应为punc,
文件:/home/******/我的文件.js行:81
我吞咽文件:

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转换到es 5,所以下面是**.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"
  },
guicsvcw

guicsvcw1#

卸载和重新安装gulp-uglify对我来说很有用。

sz81bmfz

sz81bmfz2#

您可能需要尝试添加babel-plugin-transform-async-to-generator

  1. yarn add babel-plugin-transform-async-to-generator -D
    1..巴伯尔克"plugins": ["babel-plugin-transform-async-to-generator"]

相关问题