“This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

npm run build:mylib

NPM run’s target build:mylib 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 an output directory named dist/ in the given output path. This command must be executed in the workspace directory.

When used to build the library, other builders are called and only the 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 –configuration=”production” or –prod options.

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)
Copy the code

Why is my-lib associated with url.pipe.ts in the core folder?

Create an empty test-lib and ng build it to see if it has the same error.

No problem at all.

I found that whenever I import ICON_TYPE, I get this error:

When I comment out line 2 above, the build error disappears:

Look at the ng-package.json file in other Spartacus libraries, and its lib section has a reference to @spartacus/storefront:

Add a reference to ICON_TYPE in the new test-lib service:

And immediately went wrong:

Json file in the Angular library project folder, adding references to @spartacus /core and @spartacus /storefront can solve the problem:

Successful build passed:

Many JavaScript libraries, such as jQuery, the Jasmine Testing library, and Angular, extend the JavaScript environment with new features and syntax. The TypeScript compiler doesn’t recognize them natively. When the compiler does not recognize it, it throws an error.

You can use TypeScript type definition files –.d.ts files — 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 for the various features in these libraries. Many libraries include their type-definition files in their NPM packages, which can be found by the TypeScript compiler and editor. The same is true of Angular libraries. The node_modules/@angular/core/ directory of any Angular application contains several D.ts files that describe various parts of Angular.

These D.ts files are shown below:

More of Jerry’s original articles can be found in “Wang Zixi “.