Google+
Showing posts with label Errors. Show all posts
Showing posts with label Errors. Show all posts

Friday, December 4, 2020

SOLVED - "An ERROR ocurred while running subprocess cordova" with Angular 9

In this article we review how to solve the error "An ERROR ocurred while running subprocess cordova"  using Angular 9 on Ionic 5,  on an Angular Application that includes references to cordova framework, looking like this :




How to solve the error "An ERROR ocurred while running subprocess cordova"  using Angular 9 on Ionic 5 

Fortunatly, the error message contains a hint about what to do:



To solve the problem, we'll have to re-install Gradle. 
Create a new directory C:\Gradle with File Explorer.
Download Gradle and unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool.


The next step is to configure your system environment, editing the "PATH" environment variable like follows :
Click on "Edit" to edit the "Path" variable, and add the following path to it:
C:\Gradle\gradle-6.5.1\bin



Next, before you try again to compile the app, CLOSE the cmd.exe console, so that it re-reads the now updated environment variables. Compile again :






That's All!!! 
Enjoy Angular.....

      by Carmel Schvartzman

כתב: כרמל שוורצמן

Wednesday, August 26, 2020

SOLVED : Angular 9 ERROR Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

In this article we review how to solve the Angular 9 ERROR 'Critical dependency: require function is used in a way in which dependencies cannot be statically extracted',   looking like this :






How to resolve the Angular 9 ERROR 'Critical dependency: require function is used in a way in which dependencies cannot be statically extracted' using Angular9


That;s an owfully bunch of errors all together to be solved, but that could be misleading. In effect, this errors ocurr just while adding an @Output() variable to your child component , like this :





If you pay closest attention, you'll notice that the reference added to the imports is that of protractor, and not the intended one, from @Angular/core :


That's the source of the whole bunch of errors depicted above.
Just change the import settings to that of the correct one, of @Angular/core :


Perform ng s --port 4200 --base-href   /yourwebsitename/  -o again, and get the success message :






That's All!!! 
Enjoy Angular.....

      by Carmel Schvartzman

כתב: כרמל שוורצמן



















Wednesday, June 10, 2020

Solved : How to fix the Angular 9 error "node_modules/@angular/common/common"' has no exported member 'ViewportScroller'"

In this article we review how to fix the Angular 9 error "node_modules/@angular/common/common"' has no exported member 'ViewportScroller'"  using Angular 9 with Ionic   , looking like this :



Fix the Angular 9 error "node_modules/@angular/common/common" has no exported member 'ViewportScroller' using Angular9


The error description appears as : "Module ':/ionicapp/node_modules/@angular/common/common"' has no exported member 'ViewportScroller'." .
This error happens after you installed the missing router in the Ionic app :

npm install @angular/router  --save

What the error is trying to inform us is, that the versions installed do not comply : the router installed is a different version from the one of the Angular version on your app.

We have to open the PACKAGE.JSON file, and check the versions there :



In this case, version of the @angular/core is 5.2.11, while the @angular/router that was installed, is version 9.1.9 . Of course it wouldn't work. It lacks/requires all kind of methods and properties.

Therefore, remove the router and install it according to the current version on your application:

npm install @angular/router@5.2.11  --save

After the installation, check again the PACKAGE.JSON, to see if version matches :


Now it looks OK. Compile and keep enjoying !!

That's All!!! 
Enjoy Angular.....

      by Carmel Schvartzman

כתב: כרמל שוורצמן

Saturday, April 18, 2020

How to solve the error "No directive with exportAs set to ngForm" while using Angular 7

In this article we review how to solve the error "No directive with exportAs set to ngForm" while using Angular 7.
While declaring a variable on the View, to reference the Template Driven Form that we designed there, we would face an error , at the moment Angular tries to assign the ngForm Directive to the template variable.
The error just states "No directive with exportAs set to ngForm":





How to solve the error "No directive with exportAs set to ngForm" while using Angular7


The cause of the error is quite simple. Indeed, the error message states the problem specifically : "No directive with exportAs set to ngForm".
Remember that ngForm is a Directive . Also, you know that if you code a Directive, you must decorate it with the "export" word.  Therefore, Angular has not found the corresponding Directive, to bind it to the Template.
In other words : "I could'nt find an ngForm directive with an 'export' definition".

So that we do is to open the Module where your Component was declared, let's say the app.module for example, and IMPORT there the FormsModule class, which is in '@angular/forms' :




The FormsModule class, as stated in its definitions, has as its objective to "Exports the required providers and directives for template-driven forms".


After you add this module in the "imports" section, delete and add again the Template variable, and the error will dissapear.

That's All!!! 
Enjoy Angular.....

      by Carmel Schvartzman

כתב: כרמל שוורצמן

Tuesday, April 7, 2020

Solved : Preflight Request CORS error : "The requested resource does not support http method 'OPTIONS'"

In this article we review how to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'".
Are you confronted to this error ? :


For several CORS requests, the browser sends a previous request, named "preflight request", before it sends the actual request for the resource.
It is not enought to use the standard CORS (Cross Origin Resource Sharing) on web.config , in order to solve the problem.
Here you can see the web.config settings, usually arranged to solve the problem :







How to solve the Preflight CORS error "The requested resource does not support http method 'OPTIONS'" using Angular7



The issue appears while crossing domains, and relates to POST, PUT, PATCH, and DELETE methods:
here you can see several requests , also from the Angular 7 app, as from POSTMAN :








As said, it is not enought to set the web.config to CORS.
Now,  usually the browser sends a previous request to the request that you are sending, named "preflight request", before it sends the actual request for the resource. This Preflight request is of OPTIONS type.
If the response headers do not allow the required HTTP METHOD, the browser do not send it.

The problem is, the WebApi app has not an action to process the Preflight OPTIONS request :



That is what the error is trying to say us.

So, just write an action for OPTIONS verb, that only responds an "OK", as this :



Now try again. Send a request. The breakpoint will show the OPTIONS request being processed :



Immediately after, the intended request is taken care of:





That solves this issue.
Have a good day :-)

Enjoy Angular.....

      by Carmel Schvartzman

כתב: כרמל שוורצמן

Monday, November 24, 2014

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled'


In this article we see How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled', at the Server Side of our SPA application :
How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled'




 How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled'


The serialization error that we're taking care of here, is originated when a Data Model contains an object with a self-reference property , that means, it references an entity of the same type of the containing class, or the more usual case, when we have relationships between several objects, which are referenced by others in such a way that is created a circular reference.
For example, let's say that on our SPA's server side , we have the following data Model , in which a "Blog" has a reference to its "Blogger" , and this later owns in turn many "Blogs":

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 1

That means, if you open some Blog , and open its Blogger property, you will then see the Blogs that the Blogger owns, and , between them , the original Blog that you opened earlier, and that is a circular reference.
This can happen for instance, when you have a WCF service or a Web API which use eager loading:


How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 2

The corresponding MSDN article addressing this "contains cycles and cannot be serialized if reference tracking is disabled" error  takes on account only the former study case, in which an entity references itself: let's say, a "Person"  contains a property referencing some other "Person":

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 3

MSDN states that the solution is to append to the serialization DataContract Attribute the "IsReference" boolean value set to "true". But in most cases, you're prone to find the second XML-JSON serialization case, in which many objects are related by ONE-TO-MANY relationships between them, as the following:

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 4

To solve this problem,  make a list of the classes that are REFERENCED by other classes,  the entities which are at the " 0 .. 1 " side of the one-to-many relationships. In our example, there are just two classes that behave like that: the Blogger entity  and the Blog one, sonce the "Comment" class is not referenced anywhere.
Therefore, go to the classes files and append to the DataContract attribute the "IsReference" set to true, as follows:

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 5

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 6

Then the reference tracking will got enabled and the cycles will be fixed.
In addition, if you like, it's useful to define "Metadata classes" and set the Attributes there: something  like this:
How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 7



After re-running the SPA's Server Side REST service, the WCF or WebAPI will render the data avoiding cycles :

How to fix the Server Side Web API Error 'contains cycles and cannot be serialized if reference tracking is disabled' 8


The snapshot shows that a "Blog" containing a "Blogger" property,  has a self reference and tries to reference itself, but it will be use instead the reference " z:Id=i1 " , avoiding a cycle. 
The same thing occurs for the "Comments" object, while trying to reference the containing "Blog".

Hoping it will help you...


By Carmel Shvartzman

עריכה: כרמל שוורצמן