Closed naveedahmed1 closed 6 years ago
@naveedahmed1 have you managed to reproduce this with default cli template? Is it possible to share the repo with this error as Steve request earlier. My reproduction was on my project which was fairly complicate perhaps.
I can definitely confirm that we we get this error and the issue is still unidentified. @SteveSandersonMS as I mentioned here with some more experiments, I suspect this is something to do with how SSR setup. It might not be with this cli template specifically, but this is exactly we are unsure right now.
Update: I have put a question on SO few days ago to expand the help on this issue.
@naveedahmed1 @asadsahi Thanks for filing this as a separate issue, but I still can't do anything with it until you have a repro based on the default project template. It's unclear that there is something wrong with the default template, as opposed to being a general Angular usage issue or something wrong in a more complex project configuration.
I know this might be slightly frustrating, but to avoid confusing anyone else who's reading, I'll close this for now until there is a viable repro. Hope that's OK.
@asadsahi can you update you packages.json and add --aot
at the end of start and build commands and see if it works.
For small project, this seems to solve problem but for relatively large project throws below error:
An unhandled exception occurred while processing the request.
TaskCanceledException: A task was canceled.
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
InvalidOperationException: The NPM script 'build:ssr' timed out without indicating success. Output was:
> MyProject@0.0.0 build:ssr D:\MyProject\ClientApp
> npm run build -- --app=ssr --output-hashing=media "--watch"
@naveedahmed1 with --aot flag added I get this:
without aot flag back to the same error.
Are you sure this module is compatible with Angular 5 and universal?
@naveedahmed1 this seemed a little convincing, also I tried using this ng-bootstrap with out of the box angular cli spa template and that works too, which lead me believe that it should work without issues.
@naveedahmed1 Thank you!! It worked 💯. Finally getting angular/material to resolve in lazy-loaded modules
@SteveSandersonMS After running into this error as well, I've put together a repository that replicates the issue. In my case, my home page needed to display a shared navigation bar component that was injected with a service responsible for shopping cart functions, and this service's parameters stopped resolving when I turned on SSR.
I've added the files based on my own project structure, which resembles the one recommended by Angular's style guide:
In my reproduction repo, the base template is modified such that it attempts to lazily load a component that contains the shared navigation bar component. The cart service is injected into this navbar component, causing the error. Commenting out the SSR code in Startup.cs causes no error to occur, confirming that it's something in the way the template handles SSR. Note: removing all injections from the faulty service causes the bug to stop appearing; however, this is obviously not a realistic solution (plus other services that injected services were fine), so I'm injecting the Router to ensure that the error appears.
You can find the repo in my account under 'ssr-error', or clone it straight from here:
https://github.com/artemzakharov/ssr-error.git
Just clone & run dotnet build, and you should be good to go.
My best guess is that Angular Universal doesn't currently work well in non-AoT builds. But it's hard to tell. I don't think that anything in ASP.NET or JavaScriptServices specifically has anything to do with the error you're getting. Reason:
To reproduce the error in a pure standalone Angular app:
ClientApp
subdirectory to a new location. Now it's a standalone Angular app.cd <that_directory>
npm install
npm run build:ssr
node -e "require('@angular/platform-server').renderModule(require('./dist-server/main.bundle').AppServerModule, { document: '<app-root>' })"
LAZY_MODULE_MAP
(which still results in the same error), run: node -e "require('@angular/platform-server').renderModule(require('./dist-server/main.bundle').AppServerModule, { document: '<app-root>', extraProviders: [require('@nguniversal/module-map-ngfactory-loader').provideModuleMap(require('./dist-server/main.bundle').LAZY_MODULE_MAP)] }).then(html => console.log(html))"
That will give the Can't resolve all parameters for CartService: (?) error without involving any non-Angular app code. So either your app is set up incorrectly, or there's a bug in Angular.
But you'll find that it works OK if you do an AoT build:
npm run build:ssr -- --prod
node -e "require('@angular/platform-server').renderModuleFactory(require('./dist-server/main.bundle').AppServerModuleNgFactory, { document: '<app-root>', extraProviders: [require('@nguniversal/module-map-ngfactory-loader').provideModuleMap(require('./dist-server/main.bundle').LAZY_MODULE_MAP)] }).then(html => console.log(html))"
My guess is therefore that AppServerModuleNgFactory
is required for the lazy loading to work with SSR, but it relies on AoT, and it doesn't look like there's any non-AoT equivalent as far as I can tell.
So I'd recommend that you do one or all of the following:
Good find, I'll follow up with the Angular Universal team. I've also confirmed that it's an issue specific to lazy loading - importing the (otherwise) lazily loaded component directly causes everything to be resolved successfully.
@artemzakharov please do share the link if you open this issue with universal team.
Just opened an issue with them, you can find the link above :+1:
Providers in the app aren't being resolved during SSR. It works perfectly with no-SSR but when we enable SSR it through below error:
NodeInvocationException: Can't resolve all parameters for MyService: (?, ?, ?, ?, [object Object]).
Its the same issue as reported by @asadsahi https://github.com/aspnet/JavaScriptServices/issues/1288#issuecomment-347213170
Below is the log file: