akoenig / gulp-svg2png

A gulp plugin for converting SVGs to PNGs.
MIT License
54 stars 34 forks source link

SyntaxError: Unexpected token = #29

Closed ttomdewit closed 8 years ago

ttomdewit commented 8 years ago

Hi all,

I'm getting the following error after using Salita to update svg2png to gulp-svg2png": "^2.0.2:

SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp-svg2png/index.js:18:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at requireFn (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp-load-plugins/index.js:65:14)
at Object.defineProperty.get [as svg2png] (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp-load-plugins/index.js:103:41)
at Gulp.<anonymous> (/Users/t.d.wit/Projects/syv-fe-framework/gulpfile.js:138:10)
at module.exports (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at Gulp.<anonymous> (/Users/t.d.wit/Projects/syv-fe-framework/gulpfile.js:251:8)
at module.exports (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/index.js:279:18
at finish (/Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at /Users/t.d.wit/Projects/syv-fe-framework/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:43:4

npm -v returns 3.10.8 node -v returns v4.5.0

The following tasks use svg2png:

gulp.task('svg2png', function() {
  return gulp.src('assets/img/**/*.svg')
  .pipe($.svg2png())
  .pipe(gulp.dest('assets/dist/img/icons/png'))
  .pipe($.notify({ title: 'SVG 2 PNG', message: 'Task completed', onLast: true }))
});

gulp.task('svg', ['svg2png'], function() {
  return gulp.src('assets/dist/img/**/*.svg')
  .pipe($.svgSymbols({
    templates: ['default-svg']
  }))
  .pipe(gulp.dest('assets/dist/img/icons'))
  .pipe($.notify({ title: 'SVG', message: 'Task completed', onLast: true }))
});

And this is my watch command:

gulp.watch('assets/img/**/*', ['images', 'svg']);

Whenever something changes in assets/img it triggers two tasks, namely the images task and the svg tasks, which in turn triggers the svg2png task.

zeroedin commented 8 years ago

I am having a similar issue.

Dependencies

  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-imagemin": "^3.0.3",
    "gulp-svg2png": "^2.0.2"
  }

Gulpfile

var gulp = require('gulp'),
    svg2png = require('gulp-svg2png'),
    imagemin = require('gulp-imagemin');

gulp.task('svg2png', function () {
  gulp.src([
    'build/images/**/*.svg',
    '!build/images/sources',
    '!build/images/sources/**/*'
    ], {base: './'})
    .pipe(svg2png())
    .pipe(gulp.dest('.'));
});

gulp.task('image', ['svg2png'], function(){
  gulp.src([
    './build/images/**/*',
    '!build/images/sources',
    '!build/images/sources/**/*'
  ], { base: './build'})
    .pipe(imagemin())
    .pipe(gulp.dest('./dist'));
});

gulp.task('default', ['image'])

Error

/gulpapp/node_modules/gulp-svg2png/node_modules/svg2png/lib/svg2png.js:28
function getPhantomJSArgs(options = {}) {
                                  ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/gulpapp/node_modules/gulp-svg2png/index.js:18:15)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

npm -v returns 2.15.8 node -v returns v4.4.7

zeroedin commented 8 years ago

My assumption is that this has to do with svg2png updating and something breaking on that end. Possibly after this: 8150e324 commit?

I worked around it by changing my Dependencies to lock svg2png to version 3.0.0

  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-imagemin": "^3.0.3",
    "svg2png": "3.0.0",
    "gulp-svg2png": "2.0.2"
  }
6clicks commented 8 years ago

Same error for me 'pngSprite' errored after 6.62 ms

akoenig commented 8 years ago

I guess this is related to the use of ES2015 default parameters. Please check if it works with Node.js ^6.0.0.

ttomdewit commented 8 years ago

No errors for this package after upgrading Node from v4.5.0 to Node v6.7.0. I only had to run $ npm rebuild node-sass once.

esr360 commented 8 years ago

I'm on Node 4.2.1, getting the following error on svg2png 4.0.0:

function getPhantomJSArgs(options = {}) {
                                  ^

SyntaxError: Unexpected token =

I'm not using gulp, but this seems to be the same issue.

The current long term support (LTS) version of Node is v4.6.1, would it not be wise to ensure the default version of svg2png is compatible with this version of node?

serudda commented 7 years ago

The same from my side. If I change (options = {}) to (options) and inside function added: options = {}; It works perfect. You could change to this way to fix it.

borm commented 7 years ago
npm i -D svg2png@3.0.1

after

npm i -D gulp-svg2png

helped me

petulla commented 7 years ago

Updating to the latest stable node release fixes this.