Tips for avoiding an npm package from exporting shortened component and module names when released as an Angular library

Following the steps outlined in this helpful guide, I successfully created an Angular library and published it to our GitLab package registry.

Although I managed to install the package without any issues, I faced a challenge when trying to import the library modules. Upon inspecting the node_modules directory, I noticed that the module names appeared minified in some way.

/**
 * Generated bundle index. Do not edit.
 */
export * from './index';
export { ScrapTypeTimeSeriesChartComponent as ɵf } from './lib/components/scrap-type-time-series-chart/scrap-type-time-series-chart.component';
export { ScrapTypeTimeSeriesChartModule as ɵe } from './lib/components/scrap-type-time-series-chart/scrap-type-time-series-chart.module';
export { ScrapTypeTimeSeriesChartService as ɵg } from './lib/components/scrap-type-time-series-chart/scrap-type-time-series-chart.service';
export { WorkplaceActiveStatusWidgetComponent as ɵb } from './lib/components/workplace-active-status-widget/workplace-active-status-widget.component';
export { WorkplaceActiveStatusWidgetModule as ɵa } from './lib/components/workplace-active-status-widget/workplace-active-status-widget.module';
export { DatePipe as ɵd } from './lib/shared/pipes/date.pipe';
export { TimerPipe as ɵc } from './lib/shared/pipes/timer.pipe';

//# sourceMappingURL=company-core-ui.d.ts.map

After researching the issue, I came across a relevant discussion on ng-packagr's GitHub. Unfortunately, the issue seems to have been closed without a solution. Can anyone shed light on the root cause of this problem and provide guidance on how to properly configure my Angular library project?

I am currently using Angular 12, and below are the configuration details of the library project.

tsconfig.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "rootDir": ".",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "target": "es2015",
        "module": "esnext",
        "typeRoots": ["node_modules/@types"],
        "lib": ["es2020", "dom"],
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "baseUrl": ".",
        "paths": {
            "@company/core-ui": ["dist/core-ui", "libs/core-ui/src/index"],
            "@company/core-ui/*": ["libs/core-ui", "libs/core-ui/*"]
        }
    },
    "exclude": ["node_modules", "tmp"]
}

tsconfig.lib.json

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "outDir": "../../dist/out-tsc",
        "target": "es2015",
        "declaration": true,
        "inlineSources": true,
        "types": [],
        "lib": ["dom", "es2018"]
    },
    "angularCompilerOptions": {
        "skipTemplateCodegen": true,
        "strictMetadataEmit": true,
        "enableResourceInlining": true,
        "enableIvy": false
    },
    "exclude": ["src/test-setup.ts", "**/*.spec.ts", "**/*.stories.ts", "**/*.stories.js"],
    "include": ["**/*.ts"]
}

Answer №1

To prevent uglification, the solution involved explicitly exporting Tokens. This required adding the following code to the outermost barrel:

export { ScrapTypeTimeSeriesChartComponent } from './lib/components/scrap-type-time-series-chart/scrap-type-time-series-chart.component';
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 16: Troubleshooting RxJs Problem with Updating Total in Header Component

Hello, I'm facing an issue with my Observable and need some guidance. Currently, I have a functional cart and checkout system that works well when adding items to the cart. It successfully manages total items and costs. These components are located a ...

Is it possible to restrict node.js from installing packages locally and instead use global packages?

As I continue working on various node.js projects, I have noticed that each one has its own unique package.json file specifying the required packages. Whenever I run node <mainfile>.js, npm proceeds to install all these packages in the project direct ...

A warning has been issued: CommonsChunkPlugin will now only accept one argument

I am currently working on building my Angular application using webpack. To help me with this process, I found a useful link here. In order to configure webpack, I created a webpack.config.js file at the package.json level and added the line "bundle": "web ...

How can you rearrange the order of objects in an array to only include duplicates?

https://i.sstatic.net/XwCDZ.png I don't want to alter the original order of objects in an array. However, I do need to retrieve items in a specific sequence when both the location and place are identical. I attempted a solution but it requires an ad ...

Encountering a "breaks the Content Security Policy directive: 'default-src 'none''" message while trying to deploy an Angular application on Heroku

I've been encountering difficulties while attempting to deploy my Angular app on Heroku. An error message keeps popping up stating that the image '' violates the Content Security Policy directive: "default-src 'none'". Even though ...

What are the steps to utilize the "@" shortcut in webpack configuration?

After running "npm run build" with my package.json, I encountered the following message: How can I use '@' with webpack? ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector. js?type=script&index=0!./src/App. ...

Using the transform property with the scale function causes elements positioned in the bottom right corner to vanish

Issue specific to Google Chrome and Windows 10 I'm currently working on a flipbook that adjusts content size using transform:scale() based on the user's screen size. There is also a zoom feature that allows users to adjust the scale factor. I ha ...

The element type 'HTMLElement' does not contain a property named 'pseudoStyle'

Currently experimenting with adjusting the height of a pseudo element using Typescript. An error is popping up in my IDE (vscode) as I go along. This is the code snippet I am working with. // choose element let el: HTMLElement = document.getElementById( ...

I encountered an issue when trying to dynamically add a text field in Angular 2. The error message received was "ERROR TypeError: Cannot read property '0' of

I am currently utilizing Angular2 in my project, and I am attempting to dynamically add a text field. However, I keep encountering an error: Error Message (TS): ngOnInit() { this.myForm = this._fb.group({ myArray: this._fb.array([ ...

Git bash encounters issues when attempting to run the npm install command

I'm encountering a persistent error in Git Bash while attempting to perform an npm install: 64 verbose stack Error: command failed 64 verbose stack at ChildProcess.<anonymous> (C:\Users\baseuser\AppData\Roaming\npm&b ...

Error: The property you are trying to set is undefined and cannot

When I attempt to set a property 'error' that is undefined, I receive a TypeError. The problematic line of code looks like this: this.error = error.code; This issue arises in an Angular Reactive Form while making a call to a web service. Below i ...

Error: Unable to parse string in URI within vscode API

Console LOG displays: \Users\skhan\Library\Application Support\Code\User\summary.txt The loop is used to replace the slashes. It works fine in Windows but not in Ubuntu and Mac. This is an example on OSX 10.11.6. Howev ...

Issue with ngx-extended-pdf-viewer: text not appearing due to incorrect cmaps path

I have been using the most recent stable version of ngx-extended-pdf-viewer (4.1.2) along with Angular 9.1. Everything was functioning perfectly, but after building the application, certain PDF files were not displaying any text. Upon investigation, it was ...

`Drizzle ORM and its versatile approach to SELECT statements`

Looking to improve the handling of options in a function that queries a database using Drizzle ORM. Currently, the function accepts options like enabled and limit, with potential for more options in the future. Here's the current implementation: type ...

The selected value is visible on the component, but once it is passed to the server action, it disappears

I am utilizing Nextjs14 and Supabase for my project. Currently, I have a select element where users can make a selection. The selected value is then passed as part of the formValue, which is expected to be received in the server actions as part of the For ...

Versions of Angular that are compatible with Ionic 2 (do not have an exported member)

How do I determine the compatible Angular version for each Ionic version? I keep encountering errors like "has no exported member." For example: The module ".../node_modules/@angular/core/index" does not have an exported member called InjectionToken. The ...

What steps should I follow to set up a dynamic theme in an Angular Material application?

I have spent countless hours trying to find clear documentation on setting up an Angular Material app with a theme, including changing the theme dynamically. Despite searching through numerous search results and visiting various pages, I have not been able ...

Utilizing Arrays in Typescript within the Angular Framework

I have developed a Rest API that provides data to populate two drop-down lists in a form. The information retrieved from the API is grabbed by the Angular backend and assigned to the respective drop-downs. Rather than making separate Get requests for each ...

Next.js Project Encounters Compilation Error Due to Tailwind CSS Custom Class

I am currently working on a Next.js project and incorporating Tailwind CSS. Unfortunately, I have come across a compilation error that I am struggling to resolve. The error specifically pertains to a custom utility class that I defined in my theme.css file ...

Define the data type for the toObject function's return value

Is it possible to define the return type of the toObject method in Mongoose? When working with generics, you can set properties of a Document object returned from a Mongoose query. However, accessing getters and setters on these objects triggers various v ...