The ng-packagr Angular library fails to update tsconfig paths with relative paths

In my Angular workspace (v10.0.2), I have a library and an app (used for testing the library).

Within the

projects/libname/src/lib/tsconfig.lib.json
file, I have defined some paths:

"baseUrl": "./src",
"paths": {
  "@lib/*": ["lib/*"]
}

And I am importing it like this:

import { DateUtils } from '@lib/utils/date.utils';

However, I am receiving a warning:

WARNING: No name was provided for external module '@lib/utils/date.utils' in output.globals – guessing 'date_utils'

It seems that the tsconfig paths are not being replaced, causing ng-packagr to treat it as an external module. Upon checking the dist folder, I noticed that '@lib/utils/date.utils' is still present and has not been replaced with the relative path. Ignoring the warning leads to an error when serving the test app:

Cannot find module '@lib/utils/date' or its corresponding type declarations.

I have extensively searched for solutions, but have not found any yet.

Answer №1

The most effective solution I discovered is to select a prefix that ensures your paths align perfectly once the package is installed in the node_modules directory.

For instance, if your package is named xyz, your tsconfig should look like this:

"paths": {
  "xyz/*": ["lib/*"]
}

I strongly recommend utilizing sub-entries as it not only resolves this issue, but also supports tree shaking. Check out this article for more insights.

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

Error: The OOP class value for translateX in the Web Animation API is returning as undefined

I'm currently working on a basic animation project using JavaScript. I have utilized the Animation class from the Web Animation API. My goal is to create multiple instances of this class in order to animate different elements with varying values and r ...

Using Express to serve both the Angular application and its API

Currently, I have set up an Express app with the following routing configuration: app.use(express.static(path.join(__dirname, '../angular-app/dist'))); app.use('/', express.Router().get('/', function(req, res, next) { ...

To handle async actions in Typescript with React and Redux, ensure that all actions passed to axios are plain objects. If you need to perform

Looking for assistance with Typescript, React, and Redux. export function fetchAllMeals (subject: string){ axios .get(`https://www.themealdb.com/api/json/v1/1/search.php?s=${subject}`) .then((response: any) => { console.log(response.data) ...

Angular Universal involves making two HTTP calls

When using Angular Universal, I noticed that Http calls are being made twice on the initial load. I attempted to use transferState and implemented a caching mechanism in my project, but unfortunately, it did not resolve the issue. if (isPlatf ...

The HttpClient.get('/') request with {observe: 'response'} is failing to retrieve some headers

Currently, I'm in the process of writing an API GET request by utilizing HttpClient.get(). Upon passing in the option to observe the response, I've encountered an issue where accessing the .keys() does not provide me with any headers apart from C ...

Is there a suitable alternative that supports TypeScript, particularly with Angular 6, as D3Js does not directly support TypeScript?

I am currently engaged in a new project focusing on HR Analytics, utilizing Python, R, MySQL, and Angular 6 for the front end user interface. In terms of Data Visualization, I am exploring the use of D3js. However, it is important to note that D3Js does no ...

Tips for utilizing string interpolation in the style tag of an Angular component

@Component({ selector: 'app-style', template: ` <style> .test { color: {{ textColor }} } </style> ` }) export class StyleComponent { textColor = "red"; } The current method doesn't appear to b ...

The lack of space within the <mat-select> component is causing some issues. Is there a way to incorporate multiple lines within the <

Is there a way to display multiple lines of text for each option in mat-select, instead of limiting the characters and adding "..." at the end? I need the options to have additional description lines. Here is a StackBlitz demo showcasing my issue: https:// ...

Create type definitions for React components in JavaScript that utilize the `prop-types` library

Exploring a component structure, we have: import PropTypes from 'prop-types'; import React from 'react'; export default class Tooltip extends React.Component { static propTypes = { /** * Some children components */ ...

What causes the form to consistently show as invalid once it has been submitted?

register.html : <form [formGroup]="signupForm" (submit)="onSubmit()" class="form-detail"> <h2>Registration Form</h2> <div class="form-row-total"> <div class="form-row"> <in ...

Make Angular able to open a new window using window.open instead of opening a popup

Can anyone help me figure out how to use window.open to open a PDF file in a new tab for user download? Below is the Angular 4 code I'm currently using: download() { const data = {html: this.template.toArray()[0].nativeElement.innerHTML}; th ...

Searching through an array of objects with ng2-completer does not yield any search results

Having some trouble with the ng2-completer plugin when trying to enable auto-complete functionality in a search box. The issue arises when attempting to use an array of objects instead of just strings, resulting in a 'No Results found' message. E ...

Activate the onclick event for HTML select-options when there is only a single option available

My HTML select dropdown features 5 options, which are a list of car manufacturers. When a user clicks on an option, the onchangeHandler triggers to capture the selected value. Based on this selection, another dropdown displaying car models is shown to the ...

Ways to resolve the issue of the 'setConfirmDelete' property not being found on type 'JSX.IntrinsicElements' in React.js

index.tsx const setConfirmDelete = (state, close) => { return ( <Modal show={state} onHide={close}> <Modal.Header> <Modal.Title>Title</Modal.Title> </Modal.Header> <Modal.Body> 'T ...

Deactivate the selection option in Syncfusion NumericTextbox

I have integrated an Angular NumericTextbox component from Syncfusion into my application. A problem we encountered is that when the input is clicked, it automatically gets selected. Is there a way to disable this behavior? Problem: https://gyazo.com/a72b ...

Issue arises when TypeScript attempts to verify the presence of an array element

I am facing an issue with the following array declaration: // Using const as I require it to be a specific type elsewhere const fruits = ["strawberry", "banana", "orange", "grapefruit"] as const; When attempting to ...

Establish a Svelte and TypeScript "observe" script for developing vscode extensions

Hi there! As a newbie in TypeScript, Svelte, and VSCode extension development, I have my first question to ask ...

Trouble with launching Jasmine tests within define block in compiled Typescript

Currently, I am immersed in a testing project that involves setting up a pure Javascript Jasmine Karma environment to test a pre-compiled Typescript setup. Despite my efforts, I am facing an issue where the test cases refuse to start running. While the co ...

Determining the total number of items in an array in Angular efficiently without causing any lag

Currently, I am using the function checkDevice(obj) to validate if a value is present or not. In addition to this functionality, I also require a separate method to determine the number of occurrences of Device in the Array. component.ts public checkDevi ...

Angular 6: Unable to resolve parameters for Component: (?)

We have been using Angular v6.0.0-beta.3 for a while now, but we recently attempted to upgrade to version 6.1.3. Unfortunately, I faced issues upgrading with Angular schematics due to lack of support for external registries like Artifactory. As a result, ...