title: Can't find source of: `uncaught syntaxerror` (only occurs in cypress)
body: <p>Looking for suggestions on how to pinpoint the actual source of the invalid/unexpected token.</p>
  
  <p>I'm running tests with cypress, and most of the time (though not consistently), I'm getting this error from all my tests.</p>
  
  <pre><code>Uncaught SyntaxError: Invalid or unexpected token
  
  This error originated from your application code, not from Cypress.
  
  When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
  
  This behavior is configurable, and you can choose to turn this off by listening to the 'uncaught:exception' event.
  
  https://on.cypress.io/uncaught-exception-from-application
  </code></pre>
  
  <p>So let's be clear; I do understand that it's an issue with my application code, rather than my test code. My issue is that I have yet to see anything pointing to an <strong>actual location</strong> of the <strong>syntax error</strong>. Furthermore, I <strong>run the app in chrome</strong> 72 (not through cypress) and I have <strong>no issue</strong>. There only seems to be an issue when I run the app through cypress (<strong>also using chrome 72</strong> because I'm using <code>--browser chrome</code> when i run the cypress specs).</p>
  
  <p>I've added <code>fail</code>, and <code>uncaught:exception</code> handlers to my tests to catch the output, though I still can't find anything to direct me to where the actual source of the error is.</p>
  
  <p>by breaking in the <code>uncaught:exception</code> handler, there are two args passed,
  1) the error (same as above); 2) the mocha(i think) runnable:</p>
  
  <pre><code>Hook {title: ""before all" hook", fn: ƒ, body: "function () {↵    var _this = this;↵↵    debugger;…   cy.visit("/#/account-management");↵    });↵  }", async: 0, sync: true, …}
  
      $events: {error: Array(1)}
      async: 0
      body: "function () {↵    var _this = this;↵↵    debugger;↵    cy.on('fail', event_handler_functions_1.failHandler.bind(this));↵    cy.on('uncaught:exception', function (e, r) {↵      console.log(e, r);↵      debugger;↵    });↵    cy.fixture(Cypress.env("environmentSettings")).then(function (fixture) {↵      _this.environmentData = environmentData = fixture;↵      cy.launchApp(environmentData.baseUrl, environmentData.username, environmentData.password↵      /*, 300000*/↵      );↵      cy.visit("/#/account-management");↵    });↵  }"
      callback: ƒ done(err)
      ctx: Context {currentTest: Test, _runnable: Hook, test: Hook, environmentData: {…}}
      fn: ƒ ()
      hookId: "h1"
      hookName: "before all"
      id: "r3"
      parent: Suite {title: "Account Management", ctx: Context, suites: Array(0), tests: Array(3), pending: false, …}
      pending: false
      sync: true
      timedOut: false
      timer: null
      title: ""before all" hook"
      type: "hook"
      _currentRetry: 0
      _enableTimeouts: false
      _retries: -1
      _slow: 75
      _timeout: 4000
      _trace: Error: done() called multiple times at Hook.Runnable (https://localhost:44399/__cypress/runner/cypress_runner.js:30161:17) at new Hook (https://localhost:44399/__cypress/runner/cypress_runner.js:26593:12) at Suite.beforeAll (https://localhost:44399/__cypress/runner/cypress_runner.js:31573:14) at before (https://localhost:44399/__cypress/runner/cypress_runner.js:26770:17) at context.describe.context.context (https://localhost:44399/__cypress/runner/cypress_runner.js:26666:10)
      __proto__: Runnable
  
  </code></pre>
  
  <hr>
  
  <p>I've stepped through <code>before()</code> in my test, with "Pause on Exceptions" enabled in the chrome debugger. Nothing errors until after I've stepped through everything in <code>before()</code> and have to then "Resume script execution".
  Note, I don't have a <code>beforeAll()</code> hook in my test, just a <code>before()</code>.</p>
  
  <p>I haven't made an recent changes which use unusual syntax (so far as I can tell), and I haven't ran the test suite in my local environment for a few weeks, so there are many changes - too many for me to feel like sifting through them one by one would be worthwhile.</p>
  
  <hr>
  
  <p>here's the test from that error instance for reference, though they're all having the same issue.</p>
  
  <pre><code>import { failHandler } from "..\\..\\support\\event-handler-functions"
  describe('Account Management', function () {
      var environmentData: CypressTypings.EnvrionmentSettings;
  
      before(function () {
          debugger;
          cy.on('fail', failHandler.bind(this))
          cy.on('uncaught:exception', (e, r) =&gt; {console.log(e, r); debugger;})
          cy.fixture(Cypress.env("environmentSettings")).then((fixture) =&gt; {
              (&lt;any&gt;this).environmentData = environmentData = fixture
  
              cy.launchApp(environmentData.baseUrl, environmentData.username, environmentData.password/*, 300000*/);
              cy.visit("/#/account-management");
          });
      })
  
      beforeEach(() =&gt; {
          Cypress.Cookies.preserveOnce(environmentData.cookieName)
      })
  
      it('Loads Governments', function () {
          cy.get("[data-cy=government-panel]", { timeout: 20000 }).should("have.length.gte", 1);
      })
  
      it('Users Page Loads', function () {
          cy.get("[data-cy=government-panel]").first().find(".fa-users").click();
          cy.get("tbody", { timeout: 20000 }).find("tr").should("have.have.length.greaterThan", 0);
          cy.get("[data-cy=return-to-organization-button]").click();
          cy.get("[data-cy=government-panel]").should("exist");
      })
      it('Service Area Page Loads', function () {
          cy.get("[data-cy=government-panel]").first().find(".fa-globe").click();
          cy.get("tbody", { timeout: 20000 }).find("tr").should("have.have.length.greaterThan", 0);
          cy.get("[data-cy=return-to-organization-button]").click();
          cy.get("[data-cy=government-panel]").should("exist");
      })
  })
  </code></pre>
  
  <p>Also worth noting: the <code>launchApp()</code> step actually occurs - the app is logged in, and then it appears to be as the app is loading in, that the syntax error is raised and the <code>visit()</code> step is never actually executed.</p>