[SOLVED] Upgrading to 1.6.1 - Identifier 'exports' has already been declared

My app ran fine with 1.6.0.1, but after upgrading to 1.6.1 I’m getting this error on Windows 10:

W20180201-21:37:43.535(-8)? (STDERR) c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\app\app.js:1542
W20180201-21:37:43.537(-8)? (STDERR) let exports = module.exports = {};
W20180201-21:37:43.538(-8)? (STDERR)     ^
W20180201-21:37:43.539(-8)? (STDERR)
W20180201-21:37:43.539(-8)? (STDERR) SyntaxError: Identifier 'exports' has already been declared
W20180201-21:37:43.540(-8)? (STDERR)     at createScript (vm.js:80:10)
W20180201-21:37:43.540(-8)? (STDERR)     at Object.runInThisContext (vm.js:139:10)
W20180201-21:37:43.541(-8)? (STDERR)     at c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\boot.js:393:30
W20180201-21:37:43.541(-8)? (STDERR)     at Array.forEach (<anonymous>)
W20180201-21:37:43.542(-8)? (STDERR)     at c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\boot.js:220:19
W20180201-21:37:43.542(-8)? (STDERR)     at c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\boot.js:471:5
W20180201-21:37:43.543(-8)? (STDERR)     at Function.run (c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\profile.js:510:12)
W20180201-21:37:43.544(-8)? (STDERR)     at c:\Users\Ron\WraithNotes\Meteor\WraithNotes\.meteor\local\build\programs\server\boot.js:470:11

The line let exports = module.exports = {}; does appear in multiple server-side JS files, but this has always compilied fine. Is this a problem with 1.6.1 or is my code bad? A redacted sample file follows:

  import { Meteor } from "meteor/meteor";

  require('../lib/schemas.js');
  const helpers = require('./serverHelpers.js');

  let exports = module.exports = {};
  let keydata = {};
  let smsdata = {};
  let smudata = {};
  let uber = {};

// *********************************************************************** //
// *********************************************************************** //
  function initUber(accountId) {
    /* ... REDACTED ... */
  }

// *********************************************************************** //
// *********************************************************************** //
  exports.getUberAuthorizeUrl = function(accountId) {
     /* ... REDACTED ... */
  }


// *********************************************************************** //
// *********************************************************************** //
function handleCallback(params, request, response, next) {
     /* ... REDACTED ... */
} 

The REDACTED function bodies have no affect on the error.

I’m not sure why I coded the let exports = module.exports = {} line. But after reading this article I now know that module.exports defaults to an empty object and the let isn’t needed (Actually the entire line is unneeded, it just allows you to do exports.foo = function instead of module.exports.foo = function. So replacing the offending line with exports = module.exports; fixed my problem. No idea what changed between 1.6.0.1 and 1.6.1 that caused my problem, but at least its an easy fix. And I learned some more details of Javascript and Node.js. I’m leaving this detailed description in the hope that if someone else has a similar problem, they can learn from my mistake.

1 Like