title: TypeScript Error "Cannot read property 'exports' of undefined"
body: <p>I'm trying to build a Redux middleware with TypeScript. This function</p>
  
  <pre><code>import { Middleware } from "redux"
  
  function createMiddleware() {
    return ({ dispatch, getState }) =&gt; next =&gt; action =&gt; {
      if (Math.random() &gt; 0.5) {
        return next(action)
      }
  
      return next(action)
    }
  }
  
  export const middleware: Middleware = createMiddleware()
  </code></pre>
  
  <p>produces a TypeScript error:</p>
  
  <pre><code>Typescript error: Cannot read property 'exports' of undefined
  </code></pre>
  
  <p>Though the compiler does not complain when I remove the if-block.</p>
  
  <p>My <code>tsconfig.json</code></p>
  
  <pre><code>{
    "compilerOptions": {
      "module": "commonjs",
      "target": "ES5",
      "noImplicitAny": false,
      "skipLibCheck": true,
      "noUnusedLocals": true,
      "noUnusedParameters": true,
      "jsx": "react",
      "lib": ["dom", "es2015", "es2016"],
      "baseUrl": "../src",
      "exclude": [
        "node_modules"
      ]
    }
  }
  </code></pre>
  
  <p><strong>EDIT</strong> Stacktrace from the browser console</p>
  
  <pre><code>Uncaught Error: Module build failed: TypeError: Cannot read property 'exports' of undefined
      at resolveName (..\node_modules\typescript\lib\typescript.js:24948:70)
      at getResolvedSymbol (..\node_modules\typescript\lib\typescript.js:32549:67)
      at checkIdentifier (..\node_modules\typescript\lib\typescript.js:33700:26)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38185:28)
      at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
      at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
      at checkPropertyAccessExpressionOrQualifiedName (..\node_modules\typescript\lib\typescript.js:35587:24)
      at checkPropertyAccessExpression (..\node_modules\typescript\lib\typescript.js:35554:20)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38208:28)
      at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
      at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
      at resolveCallExpression (..\node_modules\typescript\lib\typescript.js:36556:28)
      at resolveSignature (..\node_modules\typescript\lib\typescript.js:36786:28)
      at getResolvedSignature (..\node_modules\typescript\lib\typescript.js:36809:26)
      at checkCallExpression (..\node_modules\typescript\lib\typescript.js:36836:29)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38213:28)
      at resolveName (..\node_modules\typescript\lib\typescript.js:24948:70)
      at getResolvedSymbol (..\node_modules\typescript\lib\typescript.js:32549:67)
      at checkIdentifier (..\node_modules\typescript\lib\typescript.js:33700:26)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38185:28)
      at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
      at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
      at checkPropertyAccessExpressionOrQualifiedName (..\node_modules\typescript\lib\typescript.js:35587:24)
      at checkPropertyAccessExpression (..\node_modules\typescript\lib\typescript.js:35554:20)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38208:28)
      at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
      at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
      at resolveCallExpression (..\node_modules\typescript\lib\typescript.js:36556:28)
      at resolveSignature (..\node_modules\typescript\lib\typescript.js:36786:28)
      at getResolvedSignature (..\node_modules\typescript\lib\typescript.js:36809:26)
      at checkCallExpression (..\node_modules\typescript\lib\typescript.js:36836:29)
      at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38213:28)
      at Object../src/store/middleware.ts (http://localhost:8080/static/js/main.js:69038:7)
      at __webpack_require__ (http://localhost:8080/static/js/main.js:660:30)
  </code></pre>