Search code examples
gulp

Gulp gives SyntaxError: Unexpected identifier; Node issue. Mac


I am having an issue running gulp in my project folder as to setup a development environment. I am on a Mac running High Sierra. I used Homebrew to install node,npm and git. Both Node and NPM are installed globally. Gulp is installed both globally and locally to my project folder.

gulp -v    
CLI version 3.9.1
Local version 3.9.1

node -v
v11.0.0

npm -v
6.4.1

I had an issue with permissions installing Gulp globally till I changed the directory location:

npm config set prefix /usr/local

I installed my package dependencies to my project folder and here is my package.json file:

{
    "name": "ewj",
    "version": "0.0.1",
    "description": "EWJ Ireland",
    "main": "index.php",
    "author": "D Nic",
    "license": "GPL-3.0",
    "devDependencies": {
        "autoprefixer": "^9.3.1",
        "browser-sync": "^2.26.3",
        "gulp": "^3.9.1",
        "gulp-concat": "^2.6.1",
        "gulp-jshint": "2.1.0",
        "gulp-newer": "^1.4.0",
        "gulp-postcss": "^8.0.0",
        "gulp-sass": "^4.0.2",
        "gulp-sourcemaps": "^2.6.4",
        "gulp-uglify": "^3.0.1",
        "jshint": "^2.9.6"
    }
}

Verifying in iTerm2:

/Applications/MAMP/htdocs/epicworldjobs/wp-content/themes/dev-project
├── autoprefixer@9.3.1
├── browser-sync@2.26.3
├── gulp@3.9.1
├── gulp-concat@2.6.1
├── gulp-jshint@2.1.0
├── gulp-newer@1.4.0
├── gulp-postcss@8.0.0
├── gulp-sass@4.0.2
├── gulp-sourcemaps@2.6.4
├── gulp-uglify@3.0.1
└── jshint@2.9.6

Even if I have a bare bones gulpfile.js:

var gulp = require('gulp');

gulp.task('default', function() {
// place code for your default task here
});

I receive this error when I try to run gulp in the project file or anywhere:

/Applications/MAMP/htdocs/epicworldjobs/wp-content/themes/dev-project/gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { vvar gulp = require('gulp');
                                                                   ^^^^
SyntaxError: Unexpected identifier
    at new Script (vm.js:80:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:316:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Module.require (internal/modules/cjs/loader.js:643:17)
    at require (internal/modules/cjs/helpers.js:22:18)

Those files are obviously to do with Node. I have uninstalled Node several times and re-installed with no change. I for the life of me can not seem to remedy this issue. It would be greatly appreciate if someone had a solution for me as I have spent far too many hours on this.


Solution

  • The gulpfile.js on your machine, not the one you posted here, has a typo: it contains vvar gulp instead of var gulp.