-
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
cannot require files with dynamic path anymore #3306
Comments
in my case I did so // environment.member.ts
import { AppModule } from '../app/member/';
export const environment = {
production: true,
module: AppModule
}; // environment.streamer.ts
import { AppModule } from '../app/streamer/';
export const environment = {
production: true,
module: AppModule
}; |
@TkachenkoAptem |
We moved to using https://github.com/angular/angular-cli/blob/master/packages/@ngtools/webpack/README.md, which is more strict due to using |
@filipesilva Why did you close this ? |
Have you tried to see if it works with ngc? You have to remember that It's also important to get people used to using AoT rules by default otherwise they will just be very disappointing when their app does not work with AoT. They wouldn't even know how to start fixing all the errors that AoT compilation would show them. That is why the CLI made the choice to default to AoT. I understand that you might not be interested in AoT at all though, but this is the choice we made and we stand by it. If you absolutely need dynamic imports via |
Thanks @filipesilva for your quick response. Yes I know what require exactly doing , and I know that webpack will create a regex of all the possible path when you do require('./'+path) and then makes them available when you actually require them in the browser. FYI , webpack will create a function called require and will make it available in the browser too. There is absolutely no reason why it wouldn't work with this method because ngc cares about your component and creates a ngFactory of them , and for that , as far I know , I'll check your declaration list and your entryComponent list ( I might be wrong because there is no doc about it). All this aside, let's say I want to load a json file ( not a component ) like bellow :
So I just want to load this file later in the browser. ( we've been doing this more than 100 years); There is absolutely no technically reason why above shouldn't work with AOT and if it doesn't , there is no reason for my company to use Angular altogether !. With this, you're simply saying Angular doesn't let you create a dynamic component anymore and you should just create a simple form and that's it. And by the way, "but this is the choice we made and we stand by it" : Thanks for caring about the community . I'm 100% sure there are heaps of other companies like us needing this simple feature. |
Ok, so you understand how the dynamic chunks are created in webpack. But have you considered how that affect AoT compilation? It's way more strict and tries to statically analyse your code. It doesn't allow for components or directives that are not in an That being said this is only reasoning, and I admit that in practice it might work except for some bug present in the CLI or the AoT loader. It's true that webpack users are used to dynamically lazy loading chunks via webpack's mechanism, I don't deny it. It does work as far as the actual loading of them is considered, aka the raw code can be made available at a later date, but getting it to work properly in the framework context is another matter entirely. The mechanism available in Angular to ensure it works is lazy loading through the router. Which doesn't work for the dynamic chunk scenario you're proposing, but to be fair I don't think there's a way to both have completely dynamic chunks and both have them be statically analysable at the moment. Overall in the CLI we tried to completely remove any trace of node/webpack specific code like So while I recognise that usecase is wholly legitimate from a webpack point of view, it's not very important from a CLI point of view. I don't have a lot of interest in discussing the issue at length because there a lot of other issues that are also awaiting a response. The best I can do is refer you to places where you can identify the issue in an effort to help:
Issues for the AoT loader are also submitted in this repo, but the usecase might be out of scope. I'm not the one who coded it so am not 100% sure. |
@filipesilva |
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?
Versions.
Hi
We used to be able to to do this :
But this is not working any more with the latest cli.
This works :
So basically , webpack wont let me require file dynamically anymore in cli .
The text was updated successfully, but these errors were encountered: