npm run build:mylib
The target build: mylib executed by NPM run is defined in package JSON:
The actual command is: yarn — CWD feature LIBS / my lib & & NG build my lib — configuration production
Ng build: compile the angular application into the output directory named dist / under the given output path. This command must be executed in the workspace directory.
When used to build a library, other builders are called and only TS config, configuration, and watch options are applied.
When you create a project using the CLI, the “production” configuration is created by default and can be used by specifying the — configuration = “production” or — prod option.
If you encounter an error message:
[error] Error: Unable to write a reference to UrlPipe in C:/Code/SPA/mySPA/spartacus/projects/core/src/routing/configurable-routes/url-translation/url.pipe.ts from C:/Code/SPA/mySPA/spartacus/projects/core/src/routing/configurable-routes/url-translation/url.module.ts
at ReferenceEmitter.emit (C:\Code\SPA\mySPA\spartacus\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:85:19)
Why my lib and the URL under the core folder pipe. Are they related?
Create an empty test lib, and then ng build it to see if there are the same errors.
No problem.
I found that as long as I import Icon_ After type, this error will appear:
When I comment out the code in line 2 above, the build error disappears:
Check ng package. Of Spartacus and other libraries JSON file, whose lib area has a reference to @ Spartacus / storefront:
Add Icon to the new test lib service_ Reference to type:
There was also an immediate error:
After research, it is found that under the angular library project folder, tsconfig lib. JSON file, add references to @ Spartacus / core and @ Spartacus / storefront to solve the problem:
Successfully build through:
Many JavaScript libraries, such as jQuery, jasmine test library and angular, will extend the JavaScript environment through new features and syntax. The typescript compiler does not recognize them natively. When the compiler does not recognize it, it throws an error.
You can use typescript type definition file – d. TS file — to tell the compiler the type definition of the library you want to load.
Typescript sensitive editors use these definition files to display the type definitions of various properties in these libraries.
Many libraries include their type definition files in their NPM packages, which can be found by typescript compilers and editors. The same is true of the angular library. Node of any angular application_ The modules / @ angular / core / directory contains several d.ts files that describe various parts of angular.
These d.ts files are shown in the following figure:
More Jerry’s original articles are: “Wang Zixi”: