title: How can i link typescript packages so it's rooted to the dist folder when i import it?
body: <p>I'm trying to link a typescript package to another typescript package with <code>yarn link</code>. It works fine, except that the imported package isn't &quot;rooted&quot; to the main entry file declared in the package.json, which is in my dist folder.</p>
  <p>I made an example to showcase this, with a folder structure that looks like this.</p>
  <pre><code>- package-1
      - dist
          index.d.ts
          index.js
      - node_modules
          ...
      - src
          index.ts
      .gitignore
      package.json
      tsconfig.json
      yarn.lock
  
  - package-2
      - dist
          add.d.ts
          add.js
          index.d.ts
          index.js
      - node_modules
           ...
      - src
          add.ts
          index.ts
      .gitignore
      package.json
      tsconfig.json
      yarn.lock
  </code></pre>
  <p><code>package.json</code> in package-2</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;name&quot;: &quot;package-2&quot;,
      &quot;version&quot;: &quot;1.0.0&quot;,
      &quot;description&quot;: &quot;&quot;,
      &quot;main&quot;: &quot;dist/index.js&quot;,
      &quot;types&quot;: &quot;dist/index.d.ts&quot;,
      &quot;scripts&quot;: {
          &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
      },
      &quot;keywords&quot;: [],
      &quot;author&quot;: &quot;&quot;,
      &quot;license&quot;: &quot;ISC&quot;,
      &quot;devDependencies&quot;: {
          &quot;typescript&quot;: &quot;^4.5.5&quot;
      }
  }
  </code></pre>
  <p><code>ts-config.json</code> in package-2</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;compilerOptions&quot;: {
          &quot;target&quot;: &quot;es5&quot;,
          &quot;forceConsistentCasingInFileNames&quot;: true,
          &quot;strict&quot;: true,
          &quot;skipLibCheck&quot;: true,
          &quot;declaration&quot;: true,
          &quot;outDir&quot;: &quot;dist&quot;
      }
  }
  </code></pre>
  <p><code>add.ts</code> in package-2/src</p>
  <pre class="lang-js prettyprint-override"><code>export const add = (a: number, b: number) =&gt; a + b;
  </code></pre>
  <p><code>index.ts</code> in package-2/src</p>
  <pre class="lang-js prettyprint-override"><code>import { add } from &quot;./add&quot;;
  
  export const a = 5;
  export const b = 6;
  
  export default add(a, b);
  </code></pre>
  <p><code>index.ts</code> in package-1/src</p>
  <pre class="lang-js prettyprint-override"><code>import result, { a, b } from &quot;package-2&quot;;
  import { add } from &quot;package-2/add&quot;; // works fine when not importing this
  /*
  // i know this works, but i would like to use the one above as it's much cleaner
  import { add } from &quot;package-2/dist/add&quot;; 
  */
  
  console.log(add(1, 2));
  console.log(`${a}+${b}=${result}`);
  </code></pre>
  <p>package-1 gives the following error when compiling with <code>npx tsc</code></p>
  <pre><code>src/index.ts:2:21 - error TS2307: Cannot find module 'package-2/add' or its corresponding type declarations.
  
  2 import { add } from &quot;package-2/add&quot;;
  </code></pre>
  <p>Is the only way of importing from root to remove the outDir from the <code>tsconfig.json</code> file, or can I somehow use the dist folder as the root?</p>