Error: Declaration file in Typescript is unable to locate the specified module within the

I am currently developing a TypeScript library for several projects I am involved in. The library contains various packages, each of which consists of multiple modules. However, I am encountering an issue with the declaration file generated by tsc.

To make it easier to understand my problem, I have created a public repository that you can access here.

The structure of my code is organized as follows:

.
├── src
│   ├── packageA
|   |   ├──moduleA.ts
│   │   └──index.ts
│   └── packageB
|       ├──moduleB.ts
│       └──index.ts
└── tsconfig.json

Here is the content of my tsconfig file:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true,
    "lib": ["ES2019"],
    "sourceMap": true,
    "baseUrl": "./src",
    "esModuleInterop": true,
    "moduleResolution": "node"
  },
  "include": ["src"],
  "exclude": ["node_modules",]
}

Within moduleA.ts, I have the following code snippet:

export class Foo {
  foo(): string {
    return "foo";
  }
}

In packageA/index.ts:

export { Foo } from "./moduleA.ts"

And in packageB/moduleB.ts:

import { Foo} from "moduleB" //Note here that I import directly form the package.

export class Bar extends Foo {
  bar(): string {
    return "bar";
  }
}

Although everything seems to work fine during development, when I attempt to build and publish the library, I encounter an issue with the resulting TypeScript declaration file:

moduleB.d.ts

import { Foo } from "packageA"; //Cannot find module 'packageA' or its corresponding type declarations.ts(2307)
export declare class Bar extends Foo {
    bar(): string;
}

I suspect this problem stems from my tsconfig settings, which I admit I do not fully comprehend. Any assistance in resolving this issue would be greatly appreciated!

Answer №1

According to the recommendation of Amir Saleem, implementing the following configuration in my tsconfig resolved the issue:

"declarationMap": true

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

The element event does not trigger an update on the view

I am trying to display the caret position of my editor on a specific place on the website. I have created a directive and service to share variables between the controller and directive. Inside the directive, I have enabled events like "keyup", "mouseup", ...

Exploring Angular2 and TypeScript integration with complex nested JSON responses

I am currently working on a project that involves a front-end app built in Angular. Upon sending a request to my back end API, I receive a nested JSON response, as shown in the attached screenshot. My query pertains to understanding how I can process this ...

Navigating to an external link directing to an Angular 5 application will automatically land on

I am struggling to comprehend why a link from an external source to my Angular app keeps redirecting to the default route page when accessed from a browser. The scenario involves a user entering an email address, triggering an API that sends an email cont ...

What is the best way to assign an index signature to a plain object?

Currently, I have this object: const events = { i: 'insert', u: 'update', d: 'delete' }; I am struggling to assign an index signature to the object. When I try the following: export interface EventsSignature { [key: ...

Hint for parameter names not functional for TypeScript static functions

I am utilizing https://i.sstatic.net/Sxfg4.png Within my code, there exists a Car class. export default class Car { static totalCars = 0; constructor(public name: string, public model: number) { Car.totalCars++ } static getRepo ...

Issues with KeyboardEvent keydown in Angular 2 causing malfunction

I need help with triggering a keydown event that changes the pressed key to a comma. If a non-numeric value is entered, it should simulate the comma and write it in the textbox. However, after the second call, the comma is not displayed. Any suggestions on ...

The compiler is unable to locate the node_module (Error: "Module name not found")

Error: src/app/app.component.ts:4:12 - error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try npm i @types/node and then add node to the types field in your tsconfig. 4 moduleId: module.id, When att ...

Guide to mocking axios in TypeScript when provided with a configuration

I encountered an issue with mocking axios when it uses the config convention `axios(passAConfigObj)`. I'm able to mock successfully when using `axios.get` or `axios.post`, but not with the former. I don't want to rely on a library for this task a ...

Tips for using combineLatest when one stream relies on another stream for its behavior?

My Angular resolver is responsible for fetching data from the backend, and I need to make the following calls: GetProject(projectId): Observable<IProject> GetSites(projectId): Observable<ISites[]> GetPersons(siteId): Observable<IPerson[]> ...

In fact, retrieve the file from an S3 bucket and save it to your local

I've been attempting to retrieve an s3 file from my bucket using this function: async Export() { const myKey = '...key...' const mySecret = '...secret...' AWS.config.update( { accessKeyId: myKey, secretAcces ...

TypeScript function object argument must be typed appropriately

In the code, there is a function that I am working with: setTouched({ ...touched, [name]: true }); . This function accepts an object as a parameter. The 'name' property within this object is dynamic and can be anything like 'email', &ap ...

Retrieving information from BlobStorage using Service.ts and triggering the NgOnit function

Within the service.ts module, I am fetching data from Azure Blobstorage and attempting to read its contents. service.ts import { Injectable } from '@angular/core'; import { environment } from '../../environments/environment'; import { ...

Searching for a streamlined approach to retrieve a segment of a string

I'm currently working with JavaScript and TypeScript. Within my code, I encountered a scenario where I have a string that might contain certain tags indicating importance or urgency. Here are a couple of examples: A: "Remind me to go to the store to ...

Svelte user interface fails to update correctly after editing a writable array type

Currently, I am working on developing a crew creator tool for a rowing club to provide some context. The Writable container that holds the array is defined as follows import { writable, Writable } from 'svelte/store'; import type { CrewMember } ...

Issue with Typescript flow analysis when using a dictionary of functions with type dependency on the key

I am utilizing TypeScript version 4.6 Within my project, there exists a type named FooterFormElement, which contains a discriminant property labeled as type type FooterFormElement = {type:"number",...}|{type:"button",...}; To create instances of these el ...

Provide the remaining arguments in a specific callback function in TypeScript while abiding by strict mode regulations

In my code, I have a function A that accepts another function as an argument. Within function A, I aim to run the given function with one specific parameter and the remaining parameters from the given function. Here's an example: function t(g: number, ...

What is the best way to retrieve an object from a loop only once the data is fully prepared?

Hey, I'm just stepping into the world of async functions and I could use some help. My goal is to return an object called name_dates, but unfortunately when I check the console it's empty. Can you take a look at my code? Here's what I have ...

Retrieve the specified JSON Node from the input string

My goal is to consolidate all endpoints into a single JSON file within my api folder. { EndPoint: { Action: { path1: '/thisispath1/{id}', path2: '/thisispath2/', } } I aim to retrieve the path name similar ...

Horizontal scroll functionality featured in a D3 bar graph

I'm currently working on implementing a bar graph with a selection dropdown that includes 3 values: By Date, By Week, By Month (where 'By Date' is the default option). When retrieving data from the backend for 'ByDate', I have a l ...

Should Errors be Handled in the Service Layer or the Controller in the MVC Model?

Currently, I am in the process of developing a Backend using Express and following the MVC Model. However, I am uncertain about where to handle errors effectively. I have integrated express-async-errors and http-errors, allowing me to throw Errors anywher ...