title: Publishing a Typescript package that depends on a 3rd party npm package
body: <p>I'm building a simple Typescript package/library that is compiled using this variant of a <strong>tsconfig</strong> (I tried all sorts of configurations with no success) with typescript v2.8:</p>
  
  <pre><code>{
    "extends": "./tsconfig.json",
    "compilerOptions": {
      "target": "es5",
      "lib": ["es6", "dom"],
      "module": "umd",
      "moduleResolution": "node",
      "declaration": true,
      "declarationDir": "dist/types",
      "outDir": "dist/lib",
      "typeRoots": [
        "node_modules/@types",
      ],
    }
  }
  </code></pre>
  
  <p>and a <strong>package.json</strong> that looks like this:</p>
  
  <pre><code>{
    "name": "FooBarLib",
    "version": "0.0.0",
    "description": "A simple library",
    "main": "dist/lib/index.js",
    "typings": "dist/types/index.d.ts",
    "author": "Gabriel C. Troia",
    "license": "MIT",
    "dependencies": {
      "@types/ramda": "^0.25.35",
      "@types/react": "^16.4.7",
      "@types/react-dom": "^16.0.6",
      "ramda": "^0.25.0",
      "react": "^16.4.1",
      "react-dom": "^16.4.1",
      "styled-components": "^3.3.3"
    },
    "devDependencies": {
      "typescript": "2.8"
    },
    "peerDependencies": {
      "ramda": "^0.25.35",
      "react": "^16.4.1",
      "styled-components": "^3.3.3"
    },
    "scripts": {
      "prebuild": "rm -rf dist",
      "build": "tsc"
    }
  }
  </code></pre>
  
  <p>As you can see above, my FooBarLib library depends on a bunch of external libraries like <code>react</code> and <code>ramda</code>. Everything compiles locally and I'm able to generate js transpiled files as well as type definition files.</p>
  
  <p>But, when I try to import it in a separate typescript project (using typescript v2.9.2) the compiler cannot find any of the 3rd party library types used in my FooBarLib (react, ramda, etc...), even though they are installed in the project's node_modules, thus failing with one of the errors: 
  <code>Cannot find module 'react'</code> or <code>Cannot find module 'ramda'</code>, etc...</p>
  
  <p><strong>Example</strong> of a d.ts generated file:</p>
  
  <pre><code>/// &lt;reference types="ramda" /&gt;
  import * as R from 'ramda';
  export declare const myCurriedFunction: R.CurriedFunction2&lt;string | undefined, string | string[] | undefined, string&gt;;
  </code></pre>
  
  <p>Moreover, it doesn't seem to matter if <code>/// &lt;reference types="ramda" /&gt;</code> is present or not. Same error occurs. </p>
  
  <p>Also, the project that imports FooBarLib has <code>@types/ramda</code> installed locally.</p>
  
  <p>It's frustrating and I can't seem to find much information on this except for this project <a href="https://github.com/alexjoverm/typescript-library-starter" rel="noreferrer">https://github.com/alexjoverm/typescript-library-starter</a>, but just using tsconfig or package.json didn't do it.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I discovered that by manually importing the 3rd party dependencies in the project's implementation allows it to compile successfully.</p>
  
  <pre><code>import { foo } from 'FooBarLib';
  
  // 3rd party dependencies
  import { StyledComponentClass } from 'styled-components';
  import * as React from 'react';
  import * as R from 'ramda';
  
  foo();
  </code></pre>
  
  <p>The problem with this solution is that besides being extra verbose for no reason, it also fails if <code>noUnusedLocals</code> is set to true.</p>