-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Recursively Resolving Modules #10649
Comments
well not fully. but it can emulate the behavior, e.g. "paths" : {
"*": [
"./node_modules/*",
"../node_modules/*",
"../../node_modules/*",
"../../../node_modules/*"
// you get the idea..
]
} |
I just added this to my tsconfig:
but I'm still getting the errors. I ran tsc with |
Can u share a repro. |
@mhegazy Here is a repro: https://github.com/bezreyhan/ts-paths After you Also the output of |
A few of issues here.
here is a working tsonfig for you: {
"compilerOptions": {
"sourceMap": true,
"noImplicitAny": true,
"strictNullChecks": true,
"module": "commonjs",
"target": "es6",
"jsx": "react",
"baseUrl": "./",
"paths": {
"*": [
"src/shared/*"
]
}
},
"include": [
"./src/first/second/third/page.ts"
]
} |
@mhegazy Not putting However, I still need recursive lookups (In the repro I wanted to keep it simple so I only put one shared folder). If my baseUrl is set to './' the resolution will begin at the root of the project. I wanted the resolution to begin at the file that is importing a module and then recursively move up the directory tree. Can you give me any pointers here? |
i miss understood then. I do not think there is an easy way to do this. |
Hmm, would this be something the TS team would consider implementing? Being able to designate another directory name other than For example, many people in the React community use Webpack's |
would it be possible to have the same compoenent "overridden" in multiple "shared" folder, e.g.:
|
Sorry for the delayed response. Yes it would. It function the same way that Node looks for the Here is the Webpack documentation: https://webpack.github.io/docs/configuration.html#resolve-modulesdirectories |
We do something similar to this in |
It would be very useful if TS supported more advanced ala webpack resolution strategies. https://webpack.github.io/docs/configuration.html#resolve-alias but no need be as much sophisticated it believe |
Edit2 I can't get the webpack to work with my below trick, it works for some files. Btw, for now it's easiest to just drop a symbolic link "Components" to the node_modules. It works even on Windows. Then one can simply do |
I know this was made in 2016 but I was going to use this approach on a new project and ran into this issue. I don't know much about TSC internals but I might spend some time to see what this might entail. I would be apt to propose a similar compiler option as |
this is a huge blocker to adopting typescript on larger projects. I've been trying to come up with a flow to typescript migration for a lot of our projects and without this option it's just infeasible. We need an option that allows customizing which modules are |
TypeScript Version: 2.1.0
I'm using ts-loader and Webpack to compile my .ts files. In My Webpack config I have the following configuration:
This allows me to import a component that lives in the shared directory without spelling out the full relative path. Example:
import Button from 'components/Button'
Webpack will walk up the directory tree and use the first
shared
directory it finds (the same way it does with thenode_modules
directories). This way, the component can live in the../../shared/components/Buttton.tsx
and Webpack will find it and bundle it.My files compile fine because I am using ts-loader but I am getting
can not find module
errors in my editor.Is there a way to tell the TS compiler to recursively look for the component in the shared directories?
I noticed the new
baseUrl
andpaths
configuration option but to my knowledge you can not usepaths
to recursively look for a directory.The text was updated successfully, but these errors were encountered: