{"id":589,"hash":"6ed2e92479f9ee52d3f733363971dee16396f9448b2000ed198352796cbbf86f","pattern":"Browserify, Babel 6, Gulp - Unexpected token on spread operator","full_message":"I'm trying to get my Browserify/Babelify/Gulp working in my project, but it won't take the spread operator. \n\nI got this error from my gulpfile:\n\n[SyntaxError: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js: Unexpected token (16:8) while parsing file: /Users/mboutin2/Desktop/Todo-tutorial/src/reducers/grocery-list-reducers.js]\n\nThis is my gulpfile.js\n\nvar gulp = require('gulp');\nvar source = require('vinyl-source-stream');\nvar browserify = require('browserify');\nvar sourcemaps = require('gulp-sourcemaps');\nvar uglify = require('gulp-uglify');\nvar buffer = require('vinyl-buffer');\nvar babelify = require('babelify');\n\ngulp.task('build', function () {\n  return browserify({entries: './src/client/app.js', extensions: ['.js'], debug: true})\n    .transform(babelify, {presets: ['es2015', 'react']})\n    .bundle()\n    .on('error', function (err) {\n      console.error(err);\n      this.emit('end');\n    })\n    .pipe(source('app.min.js'))\n    .pipe(buffer())\n    .pipe(sourcemaps.init({loadMaps: true}))\n    .pipe(uglify())\n    .pipe(sourcemaps.write('./'))\n    .pipe(gulp.dest('./public/js'));\n});\n\ngulp.task('default', ['build']);\n\nI tried to create a .babelrc file, but it do the same thing. And my script works when i delete the spread operator.\n\nThis is the file where the Unexpected token occurs (quite simple).\n\nimport utils from '../utils/consts';\n\nconst initialState = {\n  itemList: [\n    {name: 'Apple', type: 'Fruit'},\n    {name: 'Beef', type: 'Meat'}\n  ]\n};\n\nexport function groceryList(state = initialState, action = {}) {\n\n  switch(action.type) {\n\n    case utils.ACTIONS.ITEM_SUBMIT:\n      return {\n        ...state,\n        itemList: [\n          ...state.itemList,\n          {name: action.name, type: action.itemType}\n        ]\n      };\n\n    default:\n      return state;\n\n  }\n}\n\nI don't know what doesn't work in this, i read some issues on Github and the setup page on Babel website, but i can't make it work correctly. \n\nCan anyone show me how to handle this correctly? Thank you","ecosystem":"npm","package_name":"gulp","package_version":null,"solution":"That syntax is an experimental proposed syntax for the future, it is not part of es2015 or react so you'll need to enable it.\n\nnpm install --save-dev babel-plugin-transform-object-rest-spread\n\nand add \n\n\"plugins\": [\"transform-object-rest-spread\"]\n\ninto .babelrc alongside your existing presets.\n\nAlternatively:\n\nnpm install --save-dev babel-preset-stage-3\n\nand use stage-3 in your presets to enable all stage-3 experimental functionality.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/33745118/browserify-babel-6-gulp-unexpected-token-on-spread-operator","votes":77,"created_at":"2026-04-19T04:51:22.585459+00:00","updated_at":"2026-04-19T04:51:22.585459+00:00"}