<p dir="auto">Note: I am not trying to get help fixing my code.  I am only reporting what I think is a bug in typescript.</p>
<p dir="auto">See branch "AddVS15" of <a href="https://github.com/kevinpas/Klib6">https://github.com/kevinpas/Klib6</a></p>
<p dir="auto">There are two imports in the startup file "Klib6/Tests/Core/CoreTests.ts". If you comment out the second one you can successfully run and debug/step through the tests in the startup file.</p>
<p dir="auto">If you uncomment the second import and uncomment the two lines near the bottom:<br>
//var units = "mm";<br>
//var nameValueUnits = new NameValueUnits( name, value, units );</p>
<p dir="auto">when you try to run it you get the exception (on win7):</p>
<p dir="auto">Debugger listening on port 5858<br>
module.js:338<br>
throw err;<br>
^<br>
Error: Cannot find module 'NameValue'<br>
at Function.Module._resolveFilename (module.js:336:15)<br>
at Function.Module._load (module.js:278:25)<br>
at Module.require (module.js:365:17)<br>
at require (module.js:384:17)<br>
at Object. (C:\ ... \Git\GitHub\Klib6\Source\Core<br>
\NameValueUnits.js:46:19)<br>
at Module._compile (module.js:460:26)<br>
at Object.Module._extensions..js (module.js:478:10)<br>
at Module.load (module.js:355:32)<br>
at Function.Module._load (module.js:310:12)<br>
at Module.require (module.js:365:17)<br>
Press any key to continue...</p>
<p dir="auto">Issue moved from <a href="http://typescript.codeplex.com/workitem/2448" rel="nofollow">http://typescript.codeplex.com/workitem/2448</a><br>
If a require statement has a non-relative path (eg. require('mymod') ) then tsc will search all directories from the container of the requiring file all the way up to the file system root for a corresponding source file.</p>
<p dir="auto">This can result in the require pulling in a completely unexpected source file.</p>
<p dir="auto">In my scenario I had the following files:</p>
<ol dir="auto">
<li>/home/user/myproject/crypto.ts</li>
<li>/home/user/myproject/typings/DefinitelyTyped/node/node.d.ts</li>
<li>/home/user/myproject/lib/test.ts</li>
</ol>
<p dir="auto">test.ts uses a '' directive to reference the Node.js typings. The node.d.ts file happens to have an 'import crypto = require('crypto')' statement in it to get Node.js' crypto module.</p>
<p dir="auto">When tsc was invoked in the 'lib' directory with 'tsc test.ts' and it encountered the node.d.ts file reference, it ended up looking for:</p>
<p dir="auto">/home/user/myproject/typings/DefinitelyTyped/node/crypto.ts<br>
/home/user/myproject/typings/DefinitelyTyped/crypto.ts<br>
/home/user/myproject/typings/crypto.ts<br>
...<br>
/crypto.ts</p>
<p dir="auto">Since I happened to have a file with this name in one of these parent directories, tsc ended up trying to compile that code.</p>
<p dir="auto">This behavior doesn't feel intuitive to me. Node.js' own require statement does something similar but only looks in 'node_modules/' directories at each level, so is less likely to run into the issue.</p>
<p dir="auto">I'm unsure of what the best behavior would be. Perhaps align the way require() works with absolute paths to match node.js?</p>