Unable to locate the local project module

There seems to be a perplexing issue with TS not being able to find the module in my project, while it works perfectly fine in another project. My project : https://github.com/JesusTheHun/react-typescript-boilerplate-big The project I'm referring to for guidance is https://github.com/piotrwitek/react-redux-typescript-realworld-app .

In my project, the ProjectTypes module is declared in store/types.d.ts and imported in store/index.ts, but TypeScript is unable to locate it. Interestingly, in the other project, the same module is declared in store/types.d.ts and imported in store/index.ts. It functions smoothly for one project but encounters issues in mine.

Despite using identical versions of TypeScript for both projects, and meticulously comparing configurations multiple times, I am unable to identify any discrepancies. I seem to be overlooking something crucial, but unfortunately, I cannot pinpoint what it may be.

After attempting to use --traceResolution, I discovered that it utilizes "cache" to resolve the module in the other project, whereas it only searches in node_modules for my project.

Here are snippets from the code :

// tsconfig.json
{
  "include": ["src", "typings"],
  "exclude": ["src/**/*.spec.*"],
  "extends": "./node_modules/react-redux-typescript-scripts/tsconfig.json",
  "compilerOptions": {

  }
}

The extended tsconfig.json

// ./node_modules/react-redux-typescript-scripts/tsconfig.json
{
   // Configuration options listed here ...
}

Module declaration snippet

import { StateType, ActionType } from 'typesafe-actions';

declare module 'ProjectTypes' {
  export type Store = StateType<typeof import('./index').default>;
  export type RootAction = ActionType<typeof import('./actions').default>;
  export type RootState = StateType<ReturnType<typeof import('./reducers').default>>;
}

declare module 'typesafe-actions' {
  interface Types {
    RootAction: ActionType<typeof import('./root-action').default>;
  }
}

Import statement causing trouble

import { RootAction, RootState, Services } from 'ProjectTypes';

Answer №1

According to the information found at this source, moving a single export to a single file should resolve any issues you may be experiencing. If you wish to utilize more complex types, it is necessary to closely match the original repository. Make sure not to overlook the types.d.ts file in the /services directory. You can add the following code inside them:

declare module 'ProjectTypes' {
export type Services = typeof import('./index').default;
}

By following this approach, Services will function properly from ProjectTypes. This same technique can also be applied to other types.

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 2 Component remains persistent when accessed through parameterized routes

Here is my test route with parameter T1: { path: 'Test/:T1', component: TestComponent }, After routing from 'Test/1' to 'Test/2', I noticed that my TestComponent does not reinitialize. Could this be a problem with th ...

The elusive "AnimationEvent" is nowhere to be found in the realm of Angular 4's '@angular/animations'

Currently on Angular version 4.3.2 Running @angular/cli version 1.2.6 Incorporating TypeScript (v2.4.2) for a specific component that imports import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations'; Enc ...

The configuration of the property has not been declared (Error: <spyOnProperty>)

Imagine having a MenuComponent @Component({ selector: 'cg-menu', templateUrl: './menu.component.html', styleUrls: [ './menu.component.scss' ] }) export class MenuComponent implements OnInit { menu: MenuItem[]; isLog ...

Several cucumber reports are showing an error message containing special characters

I am encountering an issue in the multiple cucumber report where error messages are being displayed with special characters. Is there a way to format them properly? I am currently learning Playwright, Typescript, and CucumberJs and generating reports for m ...

How to iterate through the elements of an object within an array using Vue.js and TypeScript

There was an issue with rendering the form due to a TypeError: Cannot read properties of undefined (reading '0'). This error occurred at line 190 in the code for form1.vue. The error is also caught as a promise rejection. Error Occurred <inpu ...

NestJs encountering issues with reading environment variables

I used the instructions from the Nest documentation to set up the configuration, however, it's not functioning correctly. app.module.ts @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true }), TypeOrmModule.forRoot(config), AuthMo ...

Angular 10: Module Alias Import Not Resolving in VSCode due to Path Mapping Recognition Issue

After updating a project from Angular 8.2 to version 10, I followed the instructions on https://update.angular.io/ and everything seemed fine. However, once I implemented Path Mapping, I started encountering this error everywhere: Cannot find module ' ...

Retrieve a particular attribute from the response data using Typescript

Here is an example of the response data format: In a Typescript environment, how can I extract the value of the "_Name" property from the first item inside the "ResultList" array of the response data? By utilizing this.responseData$.subscribe(val => c ...

Guidelines for dynamically displaying <router-link> or <a> in Vue based on whether the link is internal or external

<template> <component :is="type === 'internal' ? 'router-link' : 'a'" :to="type === 'internal' ? link : null" :href="type !== 'internal' ? link : null" > <slot /> < ...

In the latest version of Expo SDK 37, the update to [email protected] has caused a malfunction in the onShouldStartLoadWithRequest feature when handling unknown deeplinks

After updating to Expo SDK 37, my original code that was previously functioning started encountering issues with <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e7c6b6f6d7a23606f7a67786b23796b6c78667f79627a">[email prot ...

Encountering difficulty locating <arg" while providing argument to redux-saga using typescript

My takeLatest() saga function is calling postDeliverySubmitSaga(), and I need to pass arguments to it. This is how I'm defining my functions: export function* postDeliverySubmitSaga({ payload: any }: ReturnType<typeof setDeliverySubmit>) { ...

Navigating TS errors when dealing with child components in Vue and Typescript

Recently, I encountered an issue where I created a custom class-based Vue component and wanted to access its methods and computed properties from a parent component. I found an example in the Vue Docs that seemed to address my problem (https://v2.vuejs.org ...

Ways to retrieve and store basic information or a variable within a session (Solid Beginning)

After experimenting with setting the username and then accessing it in a session on the client side, I encountered an unexpected error. Here's the code snippet that caused the issue: import { useSession } from "vinxi/http"; function getSess ...

What is the best way to access the Component Reference in Angular 2 using the DOM element ID?

What is the Equivalent of - angular.element(element).scope() In Angular 2.0? I frequently used the above code snippet to retrieve scope variable in my Angular 1.x application. Is there a comparable method in Angular 2? If Not If not, how can I elimin ...

Utilizing the power of Promise and async operators in conjunction with Angular's ng

Update: I'm happy to report that my alternative solution is now also functional. It seems there was a glitch in the local storage that was causing the previous issue. Query: I am seeking guidance on how to effectively use the combination of promise ...

Unable to render React component after updating its state

After successfully retrieving data from my API, React is failing to render the cards. export default function Subjects() { const userApi = useUserService(); const auth = useRecoilValue(AuthAtom); const [loading, setLoading] = React.useState<boolea ...

Angular Tip: How to Trim the Last 4 Characters from a Bound [ngValue] String

I need to connect my [ngValue] property to a string with the last 4 characters removed. What is the most efficient way to do this using ngFor beforehand? Here is the code snippet: <select id="symbolInLineSelector" (change)="insertSymb ...

Display the FlatList component only when there is data available

When I execute a graphql query, I dynamically render a flatList based on the retrieved data. const { data, error } = useGetMyProfileQuery({ //onCompleted: _onCompleted, onError: _onGetMyProfileQueryError, }); .... return ( <SafeAreaView ...

Is there a way to assign a null value to an empty material UI text field when submitting the form, rather than an empty string?

One issue I am facing is that the default value of the text field is zero, but when I submit the form, the value of the text field becomes an empty string instead. This is not the intended behavior as I want the value to remain zero in the end. How can I r ...

Exploring the wonders of accessing POST request body in an Express server using TypeScript and Webpack

I am currently working on a Node and Express web server setup that utilizes Webpack, along with babel-loader and ts-loader. Let's take a look at some key portions of the code: webpack-config.js: const path = require("path"); const nodeExte ...