-
Notifications
You must be signed in to change notification settings - Fork 12k
Cannot import a module above the src/app
folder
#7087
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
Possibly related to #7113. |
@elliotIndex @filipesilva I thought this was directly related to #7113 and/or #7136 but it seems like even with |
As far as I can tell, this is a different problem than the AOT generates imports and whatnot, and because of the process paths the things it's trying to import don't really make sense because they are outside the project root:
This is a bug and the fix might be a trivial fix, or it might not not. But it's not something we consider very high priority to fix right now since the usecase (pretend library) is sort of a hack. Your app shouldn't be building an external library, but rather consuming it. There's some guidance about linking libraries in https://github.com/angular/angular-cli/wiki/stories-linked-library but I understand that overall library guidance is scarce. |
@filipesilva I would agree on the scarcity and I do think it is something |
According to the issue #7333, it's not just about going above I was waiting for the TypeScript We want to be able to replace SCSS variables and images referenced inside the core components. An example would be a HeaderComponent that references a An example would be a If we were to import our Core through node_modules then we couldn't use different images/SCSS variables and the problem gets much more complex. It almost works but it's just AOT that's griefing me :) We used to achieve this through SCSS entirely. We'd create a |
I have some private share modules that are installed in node_modules/@my running cli v1.4.0 |
Same issue as @playground ... any solution for this? Tried with enhanced-resolve but no success :/ |
I found this issue via #6973 - I can't discern if these are actually related issues, but the latter was closed as a dupe in favor of this issue, so I'm going to assume it is. Specifically, the problem I've been facing is that ngfactory import statements don't appear to be generated with respect to the supplied tsconfig's I saw the comment from @filipesilva
I wanted to chime in to comment that in my case this was a rather insidious problem. Regardless of whether or not specific workflows are considered "hacks", I don't think it is unreasonable for a developer to expect that That said, there is a very real possibility that there are others out there sinking quite a bit of time into trying to make what would otherwise be some rather trivial use cases work. As you mentioned, there is not a ton of guidance, and there are a thousand and one different ways to scaffold a project. Might be worth taking a second look at this issue if at least to prevent others from pulling their hair out trying to comprehend why things don't appear to be working the way they've been documented. |
I have the same issue. We were able to get half-way there by adding:
to the app's tsconfig.json files. Then, in the app.module.ts of each app, we can do stuff like:
This works as long as the shared components don't have any dependencies injected via DI. @filipesilva could you please expand on why you think doing something like this is a hack? |
@filipesilva This issue has become more relevant than ever now, with the addition of libraries in the cli. We should be able to reference in src/app/demos ... It works fine if I consume Thoughts? |
Running into similar issues, I think. "rootDir": "../.",
"baseUrl": "../.",
"paths": {
"@liborg/core": [
"../core/src"
]
}, But when building, I get lots of errors like I'm trying to avoid having to first compile |
I'm using 4 private packages inside one project with Angular CLI 7.1.4. src/app
packages/proj1
packages/proj2
packages/proj3
packages/proj4
angular.json To build the projects and rebuild when some file was changed, I just add a section for each project inside "projects": {
...
"proj1": {
"root": "packages/proj1",
"sourceRoot": "packages/proj1",
"projectType": "library",
"prefix": "proj1",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "packages/proj1/tsconfig.lib.json",
"project": "packages/proj1/ng-package.json"
}
}
}
}
...
} After that, add the main folder to your "include": [
"src/**/*",
"packages/**/*",
] |
@filipesilva wrote:
There is a very good reason to need to do this at the development level. Where different teams building different applications are using a shared library, and that shared library has a shared development model whereby the consuming application teams participate in the library's development, library changes and additions come directly out of and are synchronous with application development work. This is my particular situation - both the library and various applications are internal to my organization, and the library is published and made available via an internal registry like any node package might be. A common library is desired to provide consistency across applications and reduce overall development effort. As a practical example, application 'X' - which uses library 'Y' - needs a new feature that requires a new component. The new component will belong to the library, not the application. In order to develop the component, it needs to exist alongside the application to ensure that it meets the requirements of the application's new feature. Another use case is around fixing bugs or adding features to existing library components. Waiting for the component to be available in the library before proceeding with work on the new application feature is highly impractical and takes too long (just not very "agile" at all). There is also a lot of back and forth that would be required until it is right, so that would also consume a lot of extra cycles if they were separate development efforts. Migrating the component out of the application into the library once the feature and component are completed, is again extra work (changing the application configuration to pull the component from the library dependency instead of from itself). This requires extra testing. And because this is at the end of the development cycle for the application's needs (story has been completed), in reality it never gets done because the application team doesn't have as great a stake in the library as it does in the application (they "own" the application but not the library). So the new component lives on in the application and never gets shared via the library, defeating the purpose of the shared library entirely. A simultaneous development model is the only good solution, so enabling developers to be able to seamlessly work on the two projects at the same time and see local changes to the library component while working on their application is essential. This is really easy to set up via TypeScript Module Resolution using a Please reconsider making this a priority. |
This issue was created originally for Angular CLI 1.2.2. Things are very different now:
I don't think the original reported issue ( The underlying topic of consuming/building libraries is still very relevant though. Our stance on that is still the same as listed in the library story: you should build your lib, then consume whatever was built. Applications and libraries are built differently. It doesn't make any sense at all, from a build system point of view, to attempt to build your library with a build system that isn't meant to build libraries. The feature set of the two build systems is just plain different. You might try, and succeed, where the feature set matches, but things won't go so well once you start going into specific feature of each. We simply cannot recommend building your lib inside your app because it is incorrect and will lead to problems in all but the most trivial of cases. That being said, we don't stop you from using the @gtranter so to your point, you should be able to use |
@filipesilva thanks for the update. FWIW, this was not originally about building, as in building multiple projects from a single project. It was about importing, which prevents building. Even in my situation described above, I was not trying to build the library from the application, I was trying to build my application using a locally built version of the library. I would work on the two projects simultaneously but separately as in separate editor and build process etc. Good to know things have been improved. I'll have to find time to test (no longer actively working on the project in question). |
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. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.2.2
node: 8.1.4
os: darwin x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.2
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1
Repro steps.
@angular/cli
.ng serve --aot
.Notice that there are modules in a
lib/
directory that is even with the generatedsrc/
directory. This contains 2 modules and 2 components to reproduce the issue.The log given by the failure.
Desired functionality.
ng serve --aot
should not error when importing a module outside of the generated source code from angular cli'snew
command.Mention any other details that might be useful.
Please let me know if you need any other info.
Also please note the file paths in the error output have been stripped a bit to preserve some other requirements.
My intent is to create an angular app that will serve as documentation and at the same time have a compile step to build a library of components, but manage it all in one repository.
If this is a duplicate I apologize, but please explain what the current status is with this issue before closing if you can. Thanks!
The text was updated successfully, but these errors were encountered: