Tag Archives: angular

Solve the compilation errors encountered when NPM run build is executed by the library schematics downloaded from the official website of angular

The library schematics example I downloaded on the official website of angular encountered the following error when running the command line NPM run build:

npm run build

my- [email protected] build c:\Code\SPA\schematics-for-libraries\projects\my-lib

tsc -p tsconfig.schematics.json

schematics/my-service/index.ts:39:7 – error TS2322: Type ‘string | number | boolean | JsonArray | JsonObject | null | undefined’ is not assignable to type ‘string | undefined’.

Type ‘null’ is not assignable to type ‘string | undefined’.

39 options.project = workspace.extensions.defaultProject;

~~~~~~~~~~~~~~~

schematics/my-service/index.ts:42:44 – error TS2345: Argument of type ‘string | undefined’ is not assignable to parameter of type ‘string’.

Type ‘undefined’ is not assignable to type ‘string’.

resolvent

The data type of this project is defined in schema.ts, so it can be adjusted to be consistent with workspace.extensions.defaultproject.

Before modification:

After modification, a new problem is encountered: cannot find name ‘jsonarray’

In fact, you can add as string directly to the original code position, which means to tell the compiler that the programmer knows very well that in this context, the type of workspace.extensions.defaultproject, must be

Another error was encountered after repair:

‘options’ is declared but its value is never read.ts(6133)

The solution to this error is relatively simple:

The parameter name can be preceded by an underscore.

Finally, NPM run build is successfully executed:

More Jerry’s original articles can be found in: “Wang Zixi”:

An error occurs when angular uses canvas

Recently, the angular front-end framework was used to add graphic verification code authentication for application login. Since there was no ready-made plug-in, canvas + JS was used, which can also be used normally, but there was an error in the compilation stage:

ERROR in src/app/login/login.component.ts(84,19): error TS2339: Property 'getContext' does not exist on type 'HTMLElement'.

Although an error is reported, it can be executed normally. It’s strange. The error code is:

let c = document.getElementById("myCanvas") ;
let ctx = c.getContext("2d");

Check the source code   getContext()   This method is. Later, I wonder if it is caused by the type. Therefore, use the type assertion (which does not affect the code operation, but only works in the compilation stage) to modify the code. Enter the following:

let c = document.getElementById("myCanvas")  as HTMLCanvasElement;
let ctx = c.getContext("2d");

The compilation passed normally. As we will see later, there is another assertion method:

let c = <HTMLCanvasElement> document.getElementById("myCanvas") ;
let ctx = c.getContext("2d");

The above can be compiled because   getContext()   Yes   HTMLCanvasElement   Therefore, we need to specify the type

 

Above

 

Some solutions to the problem of “web pack / lib / node / nodetemplugin” in the development of angular

What are the eight life cycle hook functions of Vue>>>

some solutions to the problem of “webpack/lib/node/nodetemplug” of cannot find module in angular development

Reference article:

(1) Some solutions to the problem of “web pack/lib/node/nodetemplugin” in the development of angular

(2) https://www.cnblogs.com/shiyinan/p/7520913.html

Let’s make a note.

[Solved] The cause of the wrong prompt instruction [ng: areq] in angular

angular.min.js:80 Error: [ng:areq] http://errors.angularjs.org/1.2.9/ng/areq?p0=sellerService&p1=not%20a%20function%2C%20got%20undefined at angular.min.js:2 at ub (angular.min.js:14) at Pa (angular.min.js:14) at angular.min.js:57 at angular.min.js:45 at q (angular.min.js:3) at E (angular.min.js:44) at f (angular.min.js:38) at angular.min.js:38 at angular.min.js:14

This is my error in the use of angular, the main reason is not to introduce the controller module caused by, or you introduced but in the label written ng-controller = “sellerController” written wrong, written into the service layer, will also appear this error,

NPM Command Error: Allocation failed – JavaScript heap out of memory

Error occurred when executing NPM command:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

The reason is that there is not enough memory in JavaScript heap. Node is based on V8 engine. When using memory through JavaScript in node, only part of memory can be used (about 1.4 GB in 64 bit system). If memory is not enough, you can use the following methods to relax the default memory limit of V8.

Method 1:

add parameters  — max_ old_ space_ size=4096

npm run start --max_ old_ space_ size=4096

Method 2:

modify the CMD file

In the directory node_ Open ng.cmd and ngc.cmd files under modules /. Bin, and add  — max_ old_ space_ size=4096

Method 3:

through the increase memory limit plug-in

Install plug-in: NPM install – G increase memory limit

Execute command: NPX cross env limit = 4096 increase memory limit

Through the log, we can find that it will add the — Max old space size = 4096 parameter to all the places where the node command is executed