TS2307: Module '@/*' and respective type declarations could not be located

My TypeScript webpack project was struggling to resolve all custom paths today for some unknown reason. Despite trying various solutions such as re-installing packages and modifying settings, the issue persists. The same error is displayed for all files.

I have verified that my ts-config

"moduleResolution": "node"
is correctly configured.

ts-config.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "CommonJS",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "allowJs": true,
    "noImplicitAny": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost",
      "es2016",
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

package.json

{
  "scripts": {
    "test": "exit 0;",
    "build": "cross-env NODE_ENV=production webpack",
    "serve": "cross-env NODE_ENV=development webpack serve"
  },
  "devDependencies": {
    // List of dev dependencies...
  },
  "peerDependencies": {
    // Peer dependencies...
  },
  "dependencies": {
    // List of external dependencies...
  }
}

Have you considered any other potential causes for the sudden inability to locate all paths? I have even reverted my git status to a previous state where everything was working fine and reinstalled all the necessary packages, but the problem remains unresolved.

Answer №1

In my opinion, the paths need to be structured in the following way:

    "paths": {
      "@*": [
        "src/*"
      ]
    }

It is important to note that the slash before "@*" should not be included.

Answer №2

Finally figured it out: turns out I forgot to include the module declaration

Vue 3

index.d.ts / vue-shims.d.ts

declare module '*.vue' {
    import type {defineComponent} from 'vue'
    const component: ReturnType<typeof defineComponent>;
    export default component
}

Vue 2

declare module "*.vue" {
    import Vue from "vue";
    export default Vue;
}

Answer №3

I encountered a similar issue using Nextjs 14.2.8, Typescript 5.5.4, and NextAuth 5.0.0-beta.20

The error message states: Cannot find module '@/auth' or its corresponding type declarations.

{
  ...
  "include": [ ..., "app/api/**/***/**.ts"],
},

In NextAuth v5, the default API settings for OAuth2 can be found in:

<projectRoot>/app/api/auth/...nextauth/route.ts

To match the structure of the ...nextauth folder, we need to use 3 wildcards:

  • * represents ...
  • ** represents nextauth

You can refer to glob patterns here: https://code.visualstudio.com/docs/editor/glob-patterns

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

How can I properly integrate jQuery libraries, along with CSS, in a create-react-app project?

I'm currently working on incorporating the select2 jquery library into my React application, which was created using create-react-app. After adding jquery and select2 to my package.json file, I was able to get the javascript functionality to work pro ...

Error encountered while utilizing the Extract function to refine a union

I am currently working on refining the return type of my EthereumViewModel.getCoinWithBalance method by utilizing the Extract utility type to extract a portion of my FlatAssetWithBalance union based on the generic type C defined in EthereumViewModel (which ...

Iterate over a collection of HTML elements to assign a specific class to one element and a different class to the remaining elements

Forgive me if this is a silly question, but I have a function named selectFace(face); The idea is that when an item is clicked, it should add one class to that item and another class to all the other items. This is what I currently have: HTML <div c ...

Tips on dynamically looping the formcontrolname and implementing validation strategies

Looking for a way to validate multiple looping of dynamic formControlName="xxx" in select field. Check out my HTML code: <ul *ngFor="let detaillist of stressli.stresstabdetails;"> <li> <div class="form-container"> ...

The directory cannot be removed because it is not empty: npm-react-popper-tooltip

Although I am not a frontend developer, sometimes I find myself needing to perform tasks like yarn install && yarn build-dev. Currently, I am only running yarn install as indicated below. However, I am facing difficulties in getting it to function ...

Is it considered poor practice in TypeScript to manually set the type when the type inference is already accurate?

Is it necessary to explicitly set the variable type in TypeScript when it is inferred correctly? For example: const add = (a: number, b: number) => a + b; const result = add(2, 3); // Or should I explicitly declare the return value type? const add = ...

Eliminate the use of type assertion when verifying if a value is included in a union

I have a unique scenario where I am using a union type that involves an array. I need to check the values at run-time, but TypeScript is requiring me to use a type-assertion in this case. Take a look at the following code: const Pets = ["dog", &q ...

What is the alternative parameter to use instead of onChange in React Router v4?

Having an issue with the onChange Prop in TypeScript and React JS: I am encountering an error message saying "No overload matched this call." <HashRouter> <Switch> <Route path="/" ...

Convert the static method of a TypeScript class into a variable

Hey everyone, I've been working on a service for my custom application/library and this is the current approach I'm taking to create it. However, I'm thinking of converting this method into a variable to make it more user-friendly. import ...

Any problems with TypeLite involving generics or Enums?

Would you believe I have a plethora of .Net libraries/classes that I want to create typescript definitions for? Typescript is truly amazing! I experimented with simple examples and it worked flawlessly. However, the hiccup I'm facing now is that a par ...

The function cannot be accessed during the unit test

I have just created a new project in VueJS and incorporated TypeScript into it. Below is my component along with some testing methods: <template> <div></div> </template> <script lang="ts"> import { Component, Vue } from ...

What role does numerical data play in Typescript?

To find the union of types of values associated with numeric keys, the number type must be used. TS PLAYGROUND const animals = ['dog', 'cat', 'hen'] as const type Animal = typeof animals[number] // type Animal = "dog&quo ...

Error: The function parentSubmit does not exist

Hello, I am currently in the process of converting a redux-forms TypeScript class component into hooks. Here is the original class-based component that will eventually be converted to hooks: import React from 'react'; import { connect } from &ap ...

PrismaClientInitializationError: The connector encountered an issue when attempting to establish a database connection in VScode

For the past 48 hours, I've been facing this persistent issue. I've exhausted all possible solutions - tried resetting cache, flushing DNS, and every other method to reset ports. I even went as far as reinstalling VScode, but to no avail 1 Inter ...

What is the best way to center align the placeholder in an ion-input field?

What is the best way to center align the placeholder in ion-input? Here's a screenshot of my current ionic input fields with left alignment. I've attempted to move the alignment to the center, but I've been unsuccessful. Can someone please ...

What is the best way to synchronize API definitions between the server and client using TypeScript?

My setup involves a server (TypeScript, NestJS) and a client (TypeScript, Angular) that communicate with each other. Right now, I have the API response DTO classes defined in both the server to output data and in the client to decode the responses into a ...

React hook triggering re-render

A function has been implemented to retrieve and decode user claims from a token stored in local storage using a hook. export const useActiveUser = (): { user: IUserTokenClaims | null } => { const [user, setUser] = useState<IUserTokenClaims | nul ...

Definition of Jasmine custom matcher type

I have been working on adding typescript definitions to a custom jasmine matcher library. Initially, I successfully added matchers for the generic type T. Now, my goal is to specifically add matchers for DOM elements. While exploring the jasmine type def ...

Modify associated dropdown menus

I am trying to create an edit form that includes dependent select fields (such as country, state, city). The issue I am facing is that the edit only works when I reselect the first option (car brand) because I am using the event (change) with $event. How c ...

Steps for making a "confirm" button within a modal that includes a redirect URL

I have developed a modal that, upon clicking on the confirm button, should redirect the user to the page titled securities-in-portfolio. modal <div class="modal-footer justify-content-center"> <button type="button" class ...