This project is read-only.

Custom module resolution behavior (to support Node's node_modules behavior)

Topics: General
Oct 15, 2013 at 5:51 AM
Are there any plans to support different methods of module resolution in TypeScript's compiler?

For example, when you require("foo") in Node.js, it looks in the node_modules/foo subdirectory, checks for a package.json, and does a few other quirky things to locate the module. When using RequireJS, its behavior is driven by a config file which often re-maps module locations from one path to another.

If TypeScript's compiler were to support module resolution plugins, these plugins could locate .ts and .d.ts files using Node.js's or RequireJS's behavior. You could do something like:
npm install foo
tsc --module commonjs --module-resolution nodejs myCode.ts
Any node modules installed via npm can contain their own .d.ts files which will be found by TypeScript's compiler thanks to the "nodejs" module resolver.

Projects like DefinitelyTyped can benefit as well. If done correctly, the end-user can avoid some redundant ///<require... comments.

This relates to and