title: How to have absolute import paths in a library project?
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 some <code>@app</code> and <code>@lib</code> paths:</p>
  
  <pre><code>"paths": {
    "@app/*": ["projects/midi-app/src/app/*"],
    "@lib/*": ["projects/midi-lib/src/lib/*"],
    "midi-lib": [
      "dist/midi-lib"
    ],
    "midi-lib/*": [
      "dist/midi-lib/*"
    ]
  }
  </code></pre>
  
  <p>There is 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>There is a <code>public-api.ts</code> file which contains:</p>
  
  <pre><code>export * from './lib/midi-lib.module';
  </code></pre>
  
  <p>I can use this library with the test application just fine.</p>
  
  <p>But when I try using it in another client application, in another workspace, imported as a Node module, I get many errors on the unknown paths <code>Can't resolve '@lib/...'</code></p>
  
  <p>How to express the library paths so that they are exposed in a client application ? Or how to translate the library paths when packaging the library ?</p>
  
  <p>As a side question, I wonder why the extends is not done the other way around. Why is it not the <code>tsconfig.json</code> file that extends on the <code>projects/midi-lib/tsconfig.lib.json</code> file ?</p>
  
  <p>Here is how I package and then use the library:</p>
  
  <p>To package the library, add the following scripts in the scripts array of the parent <code>package.json</code> file</p>
  
  <pre><code>"copy-license": "cp ./LICENSE.md ./dist/midi-lib",
  "copy-readme": "cp ./README.md ./dist/midi-lib",
  "copy-files": "npm run copy-license &amp;&amp; npm run copy-readme",
  "build-lib": "ng build midi-lib",
  "npm-pack": "cd dist/midi-lib &amp;&amp; npm pack",
  "package": "npm run build-lib &amp;&amp; npm run copy-files &amp;&amp; npm run npm-pack",
  </code></pre>
  
  <p>and run the command: <code>npm run package</code></p>
  
  <p>then install the dependency</p>
  
  <pre><code>npm install ../midi-lib/dist/midi-lib/midi-lib-0.0.1.tgz
  </code></pre>
  
  <p>and import the module in the application module
  In the <code>app.module.ts</code> file have:</p>
  
  <pre><code>import { MidiLibModule } from 'midi-lib';
  @NgModule({
    imports: [
      MidiLibModule
  </code></pre>
  
  <p>finally insert the component in a template</p>
  
  <pre><code>&lt;midi-midi-lib&gt;&lt;/midi-midi-lib&gt;
  </code></pre>
  
  <p>When the library is installed in a client application, it has lots of <code>.d.ts</code> files in the <code>node_modules/midi-lib</code> directories:</p>
  
  <pre><code>├── bundles
  ├── esm2015
  │   └── lib
  │       ├── device
  │       ├── keyboard
  │       ├── model
  │       │   ├── measure
  │       │   └── note
  │       │       ├── duration
  │       │       └── pitch
  │       ├── service
  │       ├── sheet
  │       ├── soundtrack
  │       ├── store
  │       ├── synth
  │       └── upload
  ├── esm5
  │   └── lib
  │       ├── device
  │       ├── keyboard
  │       ├── model
  │       │   ├── measure
  │       │   └── note
  │       │       ├── duration
  │       │       └── pitch
  │       ├── service
  │       ├── sheet
  │       ├── soundtrack
  │       ├── store
  │       ├── synth
  │       └── upload
  ├── fesm2015
  ├── fesm5
  └── lib
      ├── device
      ├── keyboard
      ├── model
      │   ├── measure
      │   └── note
      │       ├── duration
      │       └── pitch
      ├── service
      ├── sheet
      ├── soundtrack
      ├── store
      ├── synth
      └── upload
  </code></pre>
  
  <p>Like this one <code>lib/service/melody.service.d.ts</code> file</p>
  
  <pre><code>import { SoundtrackStore } from '@lib/store/soundtrack-store';
  import { ParseService } from '@lib/service/parse.service';
  import { CommonService } from './common.service';
  export declare class MelodyService {
      private soundtrackStore;
      private parseService;
      private commonService;
      constructor(soundtrackStore: SoundtrackStore, parseService: ParseService, commonService: CommonService);
      addSomeMelodies(): void;
      private addSoundtrack;
      private generateNotes;
  }
  </code></pre>
  
  <p>As can be seen, it contains references to the <code>@lib</code> path mapping, which is not known in the client application.</p>
  
  <p>I also tried to use the <code>baseUrl</code> property as a work around, but that didn't help either, as when installing the library, this <code>baseUrl</code> value was not specified.</p>
  
  <p>Why is packaging the library with the command <code>npm run package</code> not resolving the <code>paths</code> mappings ?</p>