title: Shared modules and typescript aliases using firebase functions
body: <p>I'm having trouble getting my shared typescript library to work using an alias path with Firebase Functions.</p>
  
  <p>The code compiles if I reference it using relative paths, but my <code>functions/</code> directory uploads to Firebase Functions and can't use relative files outside of its directory.</p>
  
  <h3>Directory Structure</h3>
  
  <pre class="lang-sh prettyprint-override"><code>functions/
  - tsconfig.json
  - src/*.ts
  - lib/*.js
  
  shared/
  - tsconfig.json
  - src/*.ts
  - lib/*.ts
  
  src/
  - components/*.vue
  
  tsconfig.json
  tsconfig-base.json
  </code></pre>
  
  <p>In my function file, I try and reference one of my shared modules like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { MyClass } from '@shared/src/MyClass'; // Error: Cannot find module '@shared/src/MyClass'
  
  import { MyClass } from '../../shared/src/MyClass' // This Compiles, but fails deploying Cloud Functions
  </code></pre>
  
  <p>Because Cloud Functions needs to have all dependencies within the <code>functions</code> directory, I'm unable to deploy the functions, even though it all compiles using relative paths.</p>
  
  <p>What am I doing wrong with my setup, structure, or deployment?</p>
  
  <p>I've also tried adding <code>"@shared": "file:../shared"</code> to <code>functions/package.json</code> as described <a href="https://firebase.google.com/docs/functions/handle-dependencies" rel="noreferrer">here</a></p>
  
  <h3>tsconfig-base.json</h3>
  
  <pre><code>{
      "compilerOptions": {
          "module": "commonjs",
          "noImplicitReturns": true,
          "noUnusedLocals": true,
          "sourceMap": true,
          "strict": true,
          "declaration": true,
          "declarationMap": true,
          "lib": [
              "es2018"
          ],
          "target": "es2018",
          "types": [
              "node"
          ]
      },
      "compileOnSave": true,
      "files": [],
      "include": [],
      "exclude": [
          "lib",
          "node_modules"
      ]
  }
  </code></pre>
  
  <h3>shared/tsconfig.json</h3>
  
  <pre><code>{
    "extends": "../tsconfig-base.json",
    "compilerOptions": {
      "composite": true,
      "baseUrl": "./",
      "outDir": "./lib",
      "rootDir": "./src",
    },
    "compileOnSave": true,
    "include": [
      "src"
    ],
    "references": [],
    "exclude": [
      "lib",
      "node_modules"
    ]
  }
  </code></pre>
  
  <h2>functions/tsconfig.json</h2>
  
  <pre><code>{
    "extends": "../tsconfig-base.json",
    "references": [
      {
        "path": "../shared"
      }
    ],
    "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./lib",
      "rootDir": "./src",
      "paths": {
        "@shared/*": [
          "../shared/*"
        ]
      }
    },
    "compileOnSave": true,
    "include": [
      "src"
    ],
    "exclude": [
      "lib",
      "node_modules"
    ]
  }
  </code></pre>