title: How to use baseUrl for absolute import statements in a library?
body: <p>I have a library with a workspace containing two projects, one for the library itself and one for a test application.</p>
  
  <pre><code>├── projects
      ├── midi-app
      └── midi-lib
  </code></pre>
  
  <p>In the workspace <code>tsconfig.json</code> file I configured the <code>baseUrl</code> property:</p>
  
  <pre><code>"baseUrl": "./projects/midi-lib/src"
  </code></pre>
  
  <p>For the record, in this same file there are also some <code>paths</code> mappings:</p>
  
  <pre><code>"paths": {
    "midi-lib": [
      "dist/midi-lib"
    ],
    "midi-lib/*": [
      "dist/midi-lib/*"
    ],
    "@angular/*": [
      "./node_modules/@angular/*"
    ]
  }
  </code></pre>
  
  <p>There is also a <code>projects/midi-lib/tsconfig.lib.json</code> file which extends on the above <code>tsconfig.json</code> file:</p>
  
  <pre><code>"extends": "../../tsconfig.json",
  </code></pre>
  
  <p>but it contains no such <code>baseUrl</code> nor <code>paths</code> properties.</p>
  
  <p>The build command of the library sub project is successful:</p>
  
  <pre><code>$ ng build midi-lib --watch
  Building Angular Package
  Building entry point 'midi-lib'
  Compiling TypeScript sources through ngc
  Bundling to FESM2015
  Bundling to FESM5
  Bundling to UMD
  No name was provided for external module 'lib/service' in output.globals – guessing 'service'
  No name was provided for external module 'lib/store' in output.globals – guessing 'store'
  Minifying UMD bundle
  WARN: Dropping duplicated definition of variable B [0:71,24]
  WARN: Dropping duplicated definition of variable J [0:177,24]
  Copying declaration files
  Writing package metadata
  Removing scripts section in package.json as it's considered a potential security vulnerability.
  Built midi-lib
  Built Angular Package!
   - from: /home/stephane/dev/js/projects/angular/midi-lib/projects/midi-lib
   - to:   /home/stephane/dev/js/projects/angular/midi-lib/dist/midi-lib
  </code></pre>
  
  <p>I have a <code>projects/midi-lib/src/lib/service/index.ts</code> file which contains:</p>
  
  <pre><code>export { MidiService } from 'lib/service/midi.service';
  export { KeyboardService } from 'lib/service/keyboard.service';
  export { SynthService } from 'lib/service/synth.service';
  export { CommonService } from 'lib/service/common.service';
  export { GeneratorService } from 'lib/service/generator.service';
  export { MelodyService } from 'lib/service/melody.service';
  export { ParseService } from 'lib/service/parse.service';
  export { SheetService } from 'lib/service/sheet.service';
  </code></pre>
  
  <p>and allows such import statement:</p>
  
  <pre><code>import { SynthService } from 'lib/service';
  </code></pre>
  
  <p>I also have a <code>projects/midi-lib/src/lib/index.ts</code> file which contains:</p>
  
  <pre><code>export { Device } from 'lib/model';
  export { MidiService } from 'lib/service';
  export { DeviceStore, SoundtrackStore } from 'lib/store';
  </code></pre>
  
  <p>but is not being used yet, or so it seems to me.</p>
  
  <p>I'm trying to use this library with the test application but its build command <code>ng serve</code> fails with the error:</p>
  
  <pre><code>$ ng serve
  ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
  
  Date: 2019-08-17T08:02:39.883Z
  Hash: c6ef855b8b8907504425
  Time: 69624ms
  chunk {es2015-polyfills} es2015-polyfills.js, es2015-polyfills.js.map (es2015-polyfills) 323 kB [initial] [rendered]
  chunk {main} main.js, main.js.map (main) 37.9 kB [initial] [rendered]
  chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 254 kB [initial] [rendered]
  chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
  chunk {styles} styles.js, styles.js.map (styles) 17 kB [initial] [rendered]
  chunk {vendor} vendor.js, vendor.js.map (vendor) 4.45 MB [initial] [rendered]
  
  ERROR in ../midi-lib/src/lib/model/index.ts
  Module build failed (from /home/stephane/dev/js/projects/angular/midi-lib/node_modules/@ngtools/webpack/src/index.js):
  Error: /home/stephane/dev/js/projects/angular/midi-lib/projects/midi-lib/src/lib/model/index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
  </code></pre>
  
  <p>Before trying to simply use the <code>baseUrl</code> property for absolute import statements, I tried using the <code>paths</code> property, but I <a href="https://stackoverflow.com/q/56949487/958373">failed miserably</a>.</p>
  
  <p>As a side note, my VSCode doesn't show any error.</p>
  
  <p>I'm under version:</p>
  
  <pre><code>Angular CLI: 7.3.9
  Node: 10.15.1
  OS: linux x64
  Angular: 8.1.3
  </code></pre>