google / web-starter-kit

Web Starter Kit - a workflow for multi-device websites
http://developers.google.com/web/starter-kit
Apache License 2.0
18.43k stars 3.02k forks source link

'gulp serve' Works, 'gulp' Crashes! #953

Closed manavm1990 closed 6 years ago

manavm1990 commented 6 years ago

Output from 'gulp' ('gulp serve' is usually ok): app/scripts/main.js 76:7 error Parsing error: Unexpected token )

✖ 1 problem (1 error, 0 warnings)

[06:53:12] 'lint' errored after 641 ms [06:53:12] ESLintError in plugin 'gulp-eslint' Message: Failed with 1 error [06:53:12] 'default' errored after 1.57 s [06:53:12] ESLintError in plugin 'run-sequence(lint)' Message: Failed with 1 error

The 'culprit' code (just using ES6 notation to invoke jQuery 'document ready): // Your custom JavaScript goes here $(() => {

Full code in main.js is: `/!

manavm1990 commented 6 years ago

BTW, here is .babelrc (feel like this is somehow related):

{ "presets": ["es2015"], "retainLines": true }

manavm1990 commented 6 years ago

I'm pretty sure it's throwing that error on 'lint.' Is it not liking ES6 code for some reason???

[07:26:55] Requiring external module babel-register [07:26:56] Using gulpfile ~/Sites/moco-ema/gulpfile.babel.js [07:26:56] Starting 'lint'... [07:26:56] app/scripts/main.js 76:7 error Parsing error: Unexpected token )

✖ 1 problem (1 error, 0 warnings)

[07:26:56] 'lint' errored after 331 ms [07:26:56] ESLintError in plugin 'gulp-eslint' Message: Failed with 1 error

Garbee commented 6 years ago

Can you please clarify the problem? WSK does not ship with jQuery so The 'culprit' code (just using ES6 notation to invoke jQuery 'document ready): doesn't make any sense to me.

It looks as if you have modified the code provided by the repository which would be the cause of the problem. And custom code modifications aren't something we can support, you'd be better off asking for general support on StackOverflow.

manavm1990 commented 6 years ago

I might try StackOverflow next - or maybe just need to stop using jQuery, I guess! It's a bit of crutch for me!

Now, the only changes I made from the repo are: / eslint-env browser, jquery */

Everything else, is added underneath comment that says 'your custom code goes here' (or whatever)...

See, the code works without 'linting,' but obviously, I want to make sure it's production ready, so I prefer to have it work with lint.

manavm1990 commented 6 years ago

BTW, this jquery code works just fine:

`// Your custom JavaScript goes here $(document).ready(function() { $('#btn-menu, .fade-screen, #btn-menu-close').on('click touchstart', function(e) { $('.nav--traditional, .fade-screen').toggleClass('is_visible'); e.preventDefault(); });

$('.slider-container__button--collapse').on('click touchstart',
    function(e) {
      'use strict';
      $('.slider-container__text').toggleClass('is_hidden');
      e.preventDefault();
    });

$(window).scroll(function() {
  var $y1 = $(window).height();
  // Gives us top coordinate of window.

  $('[data-scroll]').each(function() {
    var $this = $(this);
    // Just a convenience var assignment.

    var thisY = this.getBoundingClientRect().top;
    // Get the vertical position of 'element.'

    var classNameArray = $this.data('scroll').split(' ');

    jQuery.each(classNameArray, function(i, val) {
      if (thisY <= $y1 && !$this.hasClass(val)) {
        $this.addClass(val);
      }
    });
  });
});

});`

It's only breaking on 'gulp' lint when I switch things over to es6 syntax: $(() => {})

manavm1990 commented 6 years ago

Ok, on that note, for testing purposes, I removed all the code, just copied/pasted main.js from repo (so no jquery), and I just have this (after comment about 'custom code'):

let spit = document.querySelector('#btn-menu, .fade-screen, #btn-menu-close');
  console.log(spit);
})();

Now, I see this:

gulp lint [08:41:40] Requiring external module babel-register [08:41:41] Using gulpfile ~/Sites/moco-ema/gulpfile.babel.js [08:41:41] Starting 'lint'... [08:41:41] app/scripts/main.js 75:4 error Parsing error: The keyword 'let' is reserved

✖ 1 problem (1 error, 0 warnings)

[08:41:41] 'lint' errored after 330 ms [08:41:41] ESLintError in plugin 'gulp-eslint' Message: Failed with 1 error

Garbee commented 6 years ago

Search for the error from eslint on your favorite search engine. There are loads of existing articles and discussions around that and how to address it.