title: Typescript cannot find module in node_modules that I created myself locally
body: <p>I'm teaching myself more about how to create node modules and how to use typescript. To accomplish this, I've attempted to create my own node module locally, and reference it in a project - however, typescript doesn't seem to recognize my module.</p>
  
  <p>The node module I've created is a simple library for doing matrix / vector operations, since I'll be toying around with such things. I've created a folder inside my project's node_modules directory, which has the following files:</p>
  
  <pre><code>node_modules
    XVectorMath
      package.json
      vectorMath.js
      vectorMath.d.ts
  </code></pre>
  
  <p>This is the output of a separate typescript project which compiled these files. These are the contents of the relevant files:</p>
  
  <p><strong>XVectorMath/package.json</strong></p>
  
  <pre><code>{
  "name": "XVectorMath",
  "version": "0.1.0",
  "main": "vectorMath.js",
  "types": "vectorMath.d.ts"
  }
  </code></pre>
  
  <p><strong>XVectorMath/vectorMath.d.ts</strong></p>
  
  <pre><code>export declare class Vector3 {
      constructor(x?: number, y?: number, z?: number);
      x: number;
      y: number;
      z: number;
      angle(): number;
      magnitude(): number;
      addVector3(b: Vector3): Vector3;
      subtractVector(b: Vector3): Vector3;
      divide(a: number): Vector3;
      scale(a: number): Vector3;
      normalize(): Vector3;
      dotProduct(b: Vector3): number;
  }
  export declare class Matrix3 {
      constructor(m?: any);
      value: number[][];
      getRowVector(n: number): Vector3;
      getColumnVector(n: number): Vector3;
      multiplyMatrix3(m: Matrix3): Matrix3;
      addMatrix3(m: Matrix3): Matrix3;
  }
  </code></pre>
  
  <p>I haven't included the contents of vectorMath.js, because it's a little lengthy and doesn't seem to be relevant.</p>
  
  <p>Elsewhere in my project I have a main.ts file, with the following import statement:</p>
  
  <p><strong>src/main.ts</strong></p>
  
  <pre><code>import {Vector3} from 'XVectorMath'
  </code></pre>
  
  <p>It's here that I get a typescript error: "Cannot find modules 'XVectorMath'".</p>
  
  <p>Here is the tsconfig.json of my project:</p>
  
  <p><strong>tsconfig.json</strong></p>
  
  <pre><code>{
      "compilerOptions":{
          "module": "commonjs",
          "outDir": "dist",
          "sourceMap": true
      },
      "include": [
          "src/**/*.ts"
      ]
  }
  </code></pre>
  
  <p>Based on what I know, I would think this would be enough for typescript to recognize the name of my module (provided by the main config entry) and utilize the types provided in vectorMath.d.ts (provided by the types config entry).</p>
  
  <p>Do I have any of this configured incorrectly, or have I missed any steps? Or do I misunderstand something entirely?</p>
  
  <p><strong>EDIT</strong>
  I've included the results from running tsc --traceResolution:</p>
  
  <pre><code>c:\Develop\NodeScripts\Typescript Project Test&gt;tsc --traceResolution
  ======== Resolving module 'XVectorMath' from 'c:/Develop/NodeScripts/Typescript
  Project Test/src/main.ts'. ========
  Module resolution kind is not specified, using 'NodeJs'.
  Loading module 'XVectorMath' from 'node_modules' folder, target file type 'TypeS
  cript'.
  Directory 'c:/Develop/NodeScripts/Typescript Project Test/src/node_modules' does
   not exist, skipping all lookups in it.
  'package.json' does not have a 'typings' field.
  'package.json' has 'types' field 'vectorMath.d.ts' that references 'c:/Develop/N
  odeScripts/Typescript Project Test/node_modules/XVectorMath/vectorMath.d.ts'.
  Found 'package.json' at 'c:/Develop/NodeScripts/Typescript Project Test/node_mod
  ules/XVectorMath/package.json'. Package ID is 'XVectorMath/vectorMath.d.ts@0.1.0
  '.
  File 'c:/Develop/NodeScripts/Typescript Project Test/node_modules/XVectorMath.ts
  ' does not exist.
  File 'c:/Develop/NodeScripts/Typescript Project Test/node_modules/XVectorMath.ts
  x' does not exist.
  File 'c:/Develop/NodeScripts/Typescript Project Test/node_modules/XVectorMath.d.
  ts' does not exist.
  'package.json' does not have a 'typings' field.
  'package.json' has 'types' field 'vectorMath.d.ts' that references 'c:/Develop/N
  odeScripts/Typescript Project Test/node_modules/XVectorMath/vectorMath.d.ts'.
  File 'c:/Develop/NodeScripts/Typescript Project Test/node_modules/XVectorMath/ve
  ctorMath.d.ts' exist - use it as a name resolution result.
  Resolving real path for 'c:/Develop/NodeScripts/Typescript Project Test/node_mod
  ules/XVectorMath/vectorMath.d.ts', result 'c:/Develop/Libraries/Javascript/@type
  s-XVectorMath/dist/vectorMath.d.ts'.
  ======== Module name 'XVectorMath' was successfully resolved to 'c:/Develop/Libr
  aries/Javascript/@types-XVectorMath/dist/vectorMath.d.ts'. ========
  </code></pre>
  
  <p>I'm not 100% sure this is saying - but I think it means that it has found the original location of my math library project, has found the .d.ts file in that location, and is using that to resolve the module name.</p>
  
  <p>Which doesn't seem quite right - the reason I installed the library output files into node-modules (done using npm install ) was to have the modules in the node_modules folder of THIS project. </p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>To add more information, I've included my project's main.ts file below to show my import, as well as my package.json:</p>
  
  <p><strong>main.ts</strong></p>
  
  <pre><code>import {Vector3} from 'XVectorMath' // Cannot find module error
  
  var test: string = "Main test";
  let vec:Vector3 = new Vector3();
  vec.x = 5; // No intellisense in VS Code, 'x' property considered an 'any' type 
             // instead of the number that it should be
  </code></pre>
  
  <p><strong>package.json</strong></p>
  
  <pre><code>{
    "name": "Test",
    "version": "0.1.0",
    "dependencies": {
      "XVectorMath": "file:../../Libraries/Javascript/@types-XVectorMath/dist"
    }
  }
  </code></pre>