-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Absolute Path Imports not working #1734
Comments
I think what you are trying to do is not possible. They support non-relative paths which is not the same as absolute paths. These non relative paths follow the given module resolution strategie stated in the tsconfig.json. You could easily figure out the relative path( |
Ideally, it would be amazing if we could just have absolute paths in reference to the root of the project, so if we move modules around, we don't have to go around correcting all the |
@iamtracy yes but is this not still a relative path? I.e. if you move the file that's importing it, you have to amend the path? I don't have an issue with Angular CLI generating erroneous |
@LunicLynx am I totally chasing a lost cause here? This relative path stuff seems totally insane... |
From how i understand this. You are supposed to aggregate the parts of your components that belong together and use re-export files with relative paths, so that you don't have many other files also pointing at theses parts with relative paths. In a best case scenario only 1 relative path in the module (ngModule). And i don't think that absolute path will actually help you when you move components around, at some points you have to change paths. Also if you are talking about libraries, then create npm packages of them, and put them into your package.json, then you will be possible to use them without specifying a relative path, because module resolution takes over. |
@LunicLynx when you mention:
are you talking about Barrels? |
Dupe of #1465. Bear in mind that there is no full solution there, but you can use the |
After struggling by searching over internet n trying to understand what exactly problem and trying different troubleshooting option, I came to know baseUrl and Path how works together Note: This solution is for Angular Cli 1.x . Not sure about other tool, If you use baseUrl:"." like below it works in VScode but not while compiling
As far my understanding and my working app and checked in angular aio code, I suggest use as baseUrl:""src like below
By having base URL as source(src directory), compiler properly resolves modules. I hope this helps to people resolve this kind of issue. |
Downgrading the CLI didn't help for me. I had added it to |
I am now starting a new project in angular, and I must say it simply shocks me that the default behavior of of the source code generated via angular-cli is all based on relative paths. It is so obvious that having source code A - referring to source code B via a relative path between A to B is nothing beyond the worst possible approach in the world - except perhaps using File System full paths - associated to your own personal computer. How is it possible to get something this trivial wrong? Are there not abundant examples of of how to properly organize code in packages in java, C# and other languages? Even in python once can specify a set of ROOT lookup paths... I am now looking at two tools, Visual Code and Eclipse Angular IDE. And we are angular 5 release already. Having the IDE Tooling cry about modules not found when you build everything perfectly fine is really really anoying. |
what worked for me was this tsconfig.json. I got it from a few new angular-cli 6 generated project.
now I can import
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
OSX v 10.11.4
Versions
Repro steps.
angular-cli
setup, this should be like so:import thing from 'src/app/path/to/thing';
ng build
tell me that the module isn't found. What am I doing wrong? I have tried all different combinations of this. What is the correct method?angular-cli
config files?The log given by the failure
The text was updated successfully, but these errors were encountered: