-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Suggestion: configurable module directories #11975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
so why not use // tsconfig.json
{
"compilerOptions": {
"paths": {
"*" : [
"./node_modules/*",
"./src/*"
]
}
}
} |
@mhegazy I've tried that. It doesn't work, I think because it's not a require.js project.
|
|
I'm closing in favor of opening a new issue for customizable module loading by writing one function, instead of this madness of trying to support every project layout. |
It would be nice to allow the developer to choose where non-relative modules are loaded from. It should be an ordered array of absolute paths (relative to
tsconfig.json
).Scenario
I have an existing legacy es6 + webpack app that is experiencing growing pains. Typescript is a solution for scaling front-end projects.
The issue is typescript can't find my modules because I developed the entire thing with
src
relative imports, and webpack'sresolve.root
option. Without proper resolution, modules are not found, and I can't gradually migrate to typescript.Proposal
Without breaking current module resolution, there should be an additional compiler option to specify where module root directories are located.
Using the example from the docs:
Right now the
node
strategy looks in the following directories, checking multiple file extensions and package json fields.Instead, the compiler should first check specified module directories in order of preference, and then fallback to node modules going up the file system for backwards compatibility. This is not a build system, it's a way for typescript to find
.ts
files.In this case typescript would look in the following places.
Relative requires would be unaffected. Node requires are unaffected thanks to fallback.
Alignment
Goals
Legacy projects can gradually migrate to using typescript. Existing typescript users can opt-in to have local modules without painful relative requires
../../../../shared/module
.Non-Goals
Node as existing language. Root relative imports as the intention of program authors.
Specifying the absolute paths to module resolution folders is simpler than implicit knowledge of
node_modules
resolution. Build tools, editors, IDEs can all read a static JSON list.Again explicit module resolution contains no surprises. Webpack and
NODE_PATH
are widely adopted. It's surprising to a number of developers that they can't choose where and how resolution happens.Related Issues:
Related Questions:
The text was updated successfully, but these errors were encountered: