Description
Issue moved from http://typescript.codeplex.com/workitem/2448
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.
This can result in the require pulling in a completely unexpected source file.
In my scenario I had the following files:
- /home/user/myproject/crypto.ts
- /home/user/myproject/typings/DefinitelyTyped/node/node.d.ts
- /home/user/myproject/lib/test.ts
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.
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:
/home/user/myproject/typings/DefinitelyTyped/node/crypto.ts
/home/user/myproject/typings/DefinitelyTyped/crypto.ts
/home/user/myproject/typings/crypto.ts
...
/crypto.ts
Since I happened to have a file with this name in one of these parent directories, tsc ended up trying to compile that code.
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.
I'm unsure of what the best behavior would be. Perhaps align the way require() works with absolute paths to match node.js?