web-starter-kit: `gulp serve` throws errors with new gulpfile

import fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 41 (8 by maintainers)

Most upvoted comments

I had similar errors until I made a .babelrc file:

$ cat .babelrc
{
  "presets": [
    "es2015"
  ]
}

I was getting:

$ gulp watch
[23:03:07] Requiring external module babel-register
/path/to/site/gulpfile.babel.js:2
import gulp from 'gulp';
^^^^^^

SyntaxError: Unexpected token import

I had a similar problem while trying to run gulp serve. I have fixed two errors and am now running without problems. I post this as it may help others.

I set up nodjs on my chromebox running Version 50.0.2661.103 (64-bit) Platform 7978.74.0 (Official Build) stable-channel panther Firmware Google_Panther.4920.24.26. I run Ubunty trusty in a chroot with Crouton, with node v4.4.5 I encountered two errors the first is mentioned above by speeQr. The download version of the Web starter kit 0.6.3 is apparantly not the same as the one on github via clone:

Using the dowload version gives errors such as this:

(trusty)louis@localhost:~/Downloads/MyDoc/testkit2$ gulp serve
[10:46:17] Failed to load external module babel-register
/home/louis/Downloads/MyDoc/testkit2/gulpfile.babel.js:27
import path from 'path';
^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at loader (/home/louis/Downloads/MyDoc/testkit2/node_modules/babel-core/node_modules/babel-register/lib/node.js:158:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/louis/Downloads/MyDoc/testkit2/node_modules/babel-core/node_modules/babel-register/lib/node.js:168:7)
    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 Liftoff.handleArguments (/home/louis/.npm-packages/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/home/louis/.npm-packages/lib/node_modules/gulp/node_modules/liftoff/index.js:193:16)

When I fixed this, using a clone of the github repository google/web-starter-kit, I was stuck with this second error that is mentioned in a thread on stackoverflow. You can find the source here:.

It gives errors such as this:

(trusty)louis@localhost:~/Downloads/MyDoc/testkit$ gulp -v
[10:46:17] Failed to load external module babel-register
[10:46:17] Requiring external module babel-core/register

The solution is from the user: Yeoman on stackoverflow in the same thread. I fixed this by downgrading to gulp version 3.9.0. The downgrade proceeds like this:

npm install -g gulp@3.9.0

Gulp version 3.9.0 is the version that is specified in the dependencies in package.json from the Web starter kit 0.6.3. I am not so familiar with the syntax in package.json, I am guessing ^3.9.0 means 3.9.0 or higher, anybody familiar with that?

Having fixed that too, everything runs fine.

@njt1982 Your package.json should look like:

"devDependencies": {
    "babel-cli": "*",
    "babel-core": "*",
    "babel-preset-es2015": "*"
},
"babel": {
    "presets": [
      "es2015"
    ]
}

babel-cli, babel-core and babel-preset-es2015 packages are required.

๐Ÿ˜„ It work for me!!!

check if you indeed have babel installed:

$ npm ls babel If you have it installed, delete the node_modules folder, and rerun your install:

sudo npm install

Tanks @xskif You save my sunday night :p

@xskif Glad itโ€™s resolved ๐Ÿ˜ƒ

You need to update to the latest version using npm i -g gulp.

itโ€™s ok now, thank you