4
votes

I am developing aproject using VS 2017 and Angular 2 + asp.netcore template. The default project runs fine, but when I import ReactiveFormsModule in app.module.ts; it throws error

Prerendering failed because of error: TypeError: _angular_core.InjectionToken is not a constructor

As per the stack trace, error is in ..\ClientApp\dist\main-server.js file.

I have upgraded the project from Angular 2.4 to angular 4.0. I am not able to understand why an import should throw an error like that.

1
The error is occurring because, after I import ReactiveFormsModule , the following line of code gets added in main-server.js file: var NG_VALIDATORS = new _angular_core.InjectionToken('NgValidators'); Am I missing something here? - Maverik
Did you find a solution to your problem ? I'm facing the exact same issue and I have no idea how to fix it. - Robouste
I didn't find a solution per se. But what I did was, instead of using template from Visual studio; I created an independent angular project (it makes future upgrades easier) and another project for Web API. It's a more modular and better approach to work with than angular template from Visual studio. Then redirect your angular compile folder to your .net core project folder, that way you can have all deployment files in one project and deploy just the .net core project and you are good to go. - Maverik
Yes I think it's a better idea, thanks for feedback - Robouste

1 Answers

0
votes

I had the same error as you, but it happened after I updated bootstrap from 3.3.7 to 4.0.0-beta2.

After I installed the most recent Visual Studio update (in my case 15.5.1), the problem went away.