The error encountered in src/app/app.module.ts is due to the inability to locate the module '@' in tsconfig.json. It is recommended to specify the path in tsconfig.json rather than using a relative path

Attempting to resolve relative path imports for a component using the path property in tsconfig.json. However, encountering the following error. Unsure why this error is occurring. Could it be because the src/components folder is not located inside the src/app folder?

Error Message :

ERROR in src/app/app.module.ts(12,33): error TS2307: Cannot find module '@advent/components'.

1) Folder Structure :

src
  - app 
      - app.module.ts
      - app.component.ts
      - app.component.html
      - app.component.css
  - components
      - modals
          - modals.component.ts
          - modals.component.html
          - modals.component.css 
      - index.ts
tsconfig.json

2) tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@advent/components/*": [
        "components/*"
      ]
    }
  }
}

3) index.ts

export * from './modals/modals.component';

4) modals.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'modals',
  templateUrl: './modals.component.html',
  styleUrls: ['./modals.component.scss']
})
export class ModalsComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

5) app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';

// Importing Components
import { AppComponent } from './app.component';
import { ModalsComponent } from '@advent/components';


@NgModule({
  declarations: [
    AppComponent,
    ModalsComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Answer №1

Make the following update in your tsconfig.json file:

  1. If the tsconfig.json file is in the src folder and the baseUrl is set to "."
"@advent/components/*": [ "./components/*" ]
  1. If the tsconfig.json file is located outside of the src folder and baseUrl is set to "."
"@advent/components/*": [ "./src/components/*" ]
  1. If the tsconfig.json file is located outside of the src folder and baseUrl is set to "./src"
"@advent/components/*": [ "./components/*" ]

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

Angular5 encountered a problem with the ngx-bootstrap DatePicker when handling DateTime objects

I currently have a SQL Server database field called 'JoiningDate' with the type of date (no time included). To collect input from users, I am utilizing the ngx-bootstrap datepicker. However, I am encountering an issue where the datepicker convert ...

Angular 2 RC 4's ViewUtils provider offers a range of functionalities for optimizing views

Is there a way to dynamically load a child component in a parent view? this.viewAddedSubscription = viewManager.viewAdded.subscribe((view) => { let injector = ReflectiveInjector.resolveAndCreate([new Provider('view', { useValue: view })] ...

Resolving undefined in Ionic 4: Returning Data from Modal

I'm attempting to create a modal window that utilizes a radio group. When a user selects a value from the radio group, I want the modal to return the selected object. Here is the code for the radio group page and HTML: export class PopoverstationsPa ...

Unable to run `create-react-app` with the `--template typescript` option

Every time I try to execute the following command: npx create-react-app my-app --template typescript only a JavaScript project is created, without any .tsx files. After consulting the CRA's TypeScript guide, it appears that the command requires Node ...

Setting up configurations in an Angular app using environment variables from a Spinnaker manifest

In the spinnaker manifest, I have certain Environment-specific variables stored that I need to replace in my Angular app when it's deployed to different environments such as dev, qa, and prod. How can I modify my code to accomplish this? The reason be ...

Errors in typing occurring due to preact children within framer-motion

While working on my preact widget (https://github.com/preactjs-templates/widget), I noticed a connection to ReactDOM. import { motion } from 'framer-motion'; import { h, VNode } from 'preact'; const Test = () => { return <mot ...

What could be causing my Angular project to not run properly without any changes made after creating a new component that I want to include in app.component.html?

Greetings, I am just starting out with Angular 17 and I am currently going through the Tour of Heroes course on the official website. Following the tutorial's instructions, I created a new component called 'heroes' after setting up my projec ...

NgbHighlight now allows for one highlight element per line

I am currently utilizing NgbHighlight to allow users to search within a list. However, I am facing an issue with the highlighting of search results. My intention is to highlight only the first match in the list. I am sticking to the basic implementation ...

Automatically pass on parameters from a universal function

If I have an object with functions that return numbers: const obj = { foo() { return 1; } bar() { return 2; } baz(num: number) { return num; } } The expected output of typeof obj would be: { foo: () => number; bar: () => number; baz ...

Exploring the concepts of TypeScript interface inheritance and the powerful capabilities of generics in type inference

I'm facing a dilemma with TypeScript interfaces, generics, classes... not exactly sure which one is causing the issue. My mind is in overdrive trying to find a solution but I can't seem to simplify things. Here's what I'm grappling with ...

Issue with next.handle not functioning properly in Angular 8 when re-requesting

In the code snippet below, the issue is that even after the token expires (401), the API for fetching the refresh token is called, but the request is not re-sent with the updated token using the inner next.handle(). export class InterceptService implements ...

Next.js Custom App now offers full support for Typescript in Accelerated Mobile Pages (

I am looking to implement AMP in my custom Next.js project using Typescript. While the official Next.js documentation does not offer support for Typescript, it suggests creating a file called amp.d.ts as a workaround. My application includes a src folder ...

Update the TypeScript definitions in the index.d.ts file using the npm command, by overriding it with the reference types

After running npm install, I noticed that the index.d.ts file contains a reference to the wrong path: /// <reference types="[WrongPath]"/>. As someone new to npm, TypeScript, and web development in general, I'm wondering if it's possible t ...

Creating a TypeScript frozen set: A step-by-step guide

Imagine having a group of values that you want to protect from being edited, as shown below: // These values should not be editable. const listenedKeys = new Set(['w', 'a', 's', 'd']) // This value can be accessed w ...

How can I send 'blocking' parameter to getStaticPaths function in Next.js using TypeScript?

Whenever I try to use fallback: 'blocking', in my Next.js page, TypeScript throws an error. I am using the latest 12.2.0 version of Next.js. What could be causing this issue? Type '() => Promise<{ paths: any; fallback: string; }>&ap ...

What could be causing my project to install an erroneous Angular version?

It appears that my project is not utilizing the latest Angular code, but I am unsure of the reason behind this. I have checked my package.json file and found the following dependencies: "devDependencies": { "@angular/common": "2.0.0", "@angular ...

Unable to view console log output within the loop

I am having trouble accessing console logs in my application when trying to loop through the data set provided below. The code snippet includes a function for calculating AVAF loan adjustments, but for some reason, no data is being printed to the console. ...

Angular: Refresh Mat-Table data following any changes

I'm currently working with a Mat-table that has expandable rows, each containing an update functionality for the data. While the POST and GET requests are functioning properly, I encounter an issue where I need to reload the page in order to see the u ...

Creating an object key using a passed literal argument in TypeScript

Can the following scenario be achieved? Given an argument, how can we identify the object key and access it? Any potential solutions? async function checkKey(arg:'key1'|'key2'){ // fetchResult returns an object with either {key1:&apo ...

Issues with the functionality of patchValue() in reactive forms when using ngValue

When working with reactive forms, I encountered an issue with binding a selected item from a dropdown. I used the entire object as the value ({NAME:'test',CODE:'002'}) for processing, and was able to retrieve the selected item in my .ts ...