The "paths" parameter in Typescript's tsconfig.json cannot be located, even if the baseUrl is specified

I'm currently working on an Ionic 7 Vue project in Typescript. One of the challenges I'm facing is creating an alias for shared interfaces using paths in the tsconfig.json file, but the added path doesn't seem to resolve. Below is a snippet of my tsconfig.json setup:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "types": ["webpack-env", "jest", "google.maps", "cypress"],
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"],//  <-------------------------------- This alias resolves fine.
      "@shared/*": ["../server/src/*/shared/index.ts"] // <- This one doesn't.
      // "@shared/*": ["../server/src/*/shared"] // <------- This also doesn't work (same error).
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"],
    // mp035 added
    "strictPropertyInitialization": false
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx",
    "../server/src/**/shared/*.ts" // <----------------- these files are found fine.
  ],
  "exclude": ["node_modules"]
}

During the build process, I encounter the following error:

Module not found: Error: Can't resolve '@shared/bookings' in '/XXXXXX/XXXXX/app/src/views/customer'

I would appreciate any insights or suggestions on what might be causing this issue.

Answer №1

After extensive research and investigation, it became apparent that in addition to configuring webpack as suggested by @Yu-Miao, I needed to ensure that the paths were respected. I opted to utilize the tsconfig-paths-webpack-plugin, following the guidance provided at

To implement this solution, I first installed the plugin using the command:

npm install --save-dev tsconfig-paths-webpack-plugin

Subsequently, I created a vue.config.js file at the root of my project with the following configuration:

const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = {
    configureWebpack: {
        resolve: {
            plugins: [new TsconfigPathsPlugin({extensions:['.ts', '.tsx', '.vue']})]
        }
    }
}

For those who prefer not to use a plugin, an alternative approach could involve restructuring the source files to simplify the tsconfig path, e.g.,

"@shared/*" : "../server/src/shared/*"
. This would allow for a manual entry in vue.config.js like so:

const path = require('path');

module.exports = {
    configureWebpack: {
        resolve: {
            alias:{
                "@": path.resolve(__dirname, "src"),
                "@shared": path.resolve(__dirname, "../server/src/shared"),
            },
        }
    }
}

In my case, I find the DRY (Don't Repeat Yourself) option provided by the plugin to be more preferable.

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

Encountered a problem during the installation of the Ionic framework

Despite seeking solutions in other questions and answers, I am still unable to resolve my issue. Node.js has been successfully installed on my system. Node version: 0.12.7 NPM version: 2.11.3 When attempting to install Cordova, there are warnings but it ...

The date in a nodejs application appears to be shifted by one day

Despite similar questions being asked before here, the solutions provided did not resolve my issue. Here is the scenario I am dealing with: https://i.sstatic.net/H9rcO.png Upon clicking save, I collect data from certain fields to generate a date using th ...

Passing an array from a parent component to a child component in Angular

Just to give you some background, I only started my Angular learning journey about a week ago, so feel free to start from the very beginning. So, how can this be achieved? Inside app.component.ts, there is a standard array that needs to be accessible by m ...

What advantages do interfaces as data types offer in Angular compared to using classes?

After watching a tutorial from my teacher, he showed us this code snippet: https://i.sstatic.net/MA3Z9.png He mentioned that the products array, defined as type any [], is not taking advantage of TypeScript's strongly typing. He suggested using an I ...

Using Typescript to read data from a file and returning an object that is undefined

I'm attempting to extract data from a file that contains the following snippet: const config = { appName: 'my app', }; If I log the variable containing this data, it shows up as expected: const config = { appName: 'my app', ...

Receiving data from a service in Angular 2 with rxjs subscribe throws an error: it is not a

I've recently started working with Angular and I'm encountering an issue when trying to pass the _newArray to my child component using a shared service. Service fetchData(): Observable < any > { return forkJoin(this.fetchQuestions(), th ...

Troubleshooting problems with loading data while implementing an iOS infinite scroll feature in Ionic 3

Within my application, there exists a chat feature in which additional messages are loaded as the user scrolls up. I have implemented Ionic's default "infinite scroll" component with a position of 'top' in order to detect when the user reach ...

The name "Identifier" has already been declared before

I am currently working on a social network project to enhance my skills in nodejs and reactjs. While debugging the backend code for /signin using Postman, I encountered an error that prevents me from launching the node server. The error message displayed i ...

Encountering an issue with the UNION operator in Typescript causes an error

Currently, I am utilizing the OR operator within Typescript to designate that a product could be of type ProductI OR CartResponseInterface.Product This is how it is structured: product: ProductI | CartResponseInterface.Product However, when attempting t ...

"Two distinct routes in Angular, but keeping the same menu item highlighted as

In my app-component.ts, I have a menu structured like this: <ul> <li> <a href="#" routerLink="/" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">Home</a> </li> <li> <a href="#" route ...

Passing references through multiple tiers [Typescript / React]

Working with atomic design principles can be challenging, especially when it comes to proper implementation. I have developed three key components: Form, ExpandableInput, and Input. The Input component serves as an HTML input wrapper, while the ExpandableI ...

Is this Firebase regulation accurate and suitable for PUT and GET requests in an Angular and Firebase environment?

Creating a system where users can only see their own posts and no one else can access them is my main goal. Authentication along with posting functionality is already in place and working, but I want to implement this without using Firebase restrictions. ...

What is the best way to adjust and filter an array based on a single value?

Here is an array that needs to be modified: [ {name: "test", value: "test", group: 0}, {name: "test1", value: "test2", group: 0}, {name: "test3", value: "test3", group: 1}, {name: "te ...

Ionic: Automatically empty input field upon page rendering

I have an input field on my HTML page below: <ion-input type="text" (input)="getid($event.target.value)" autofocus="true" id="get_ticket_id"></ion-input> I would like this input field to be cleared eve ...

What is the functionality of "classnames" in cases where there are multiple classes sharing the same name?

Currently, I am reviewing some code that utilizes the npm utility classnames found at https://www.npmjs.com/package/classnames. Within the scss file, there are various classes with identical names (small and large), as shown below: .buttonA { &.smal ...

Can someone guide me on leveraging TypeScript typing details provided by a Node.js package?

I've come across various versions of this query, but I'm struggling to comprehend it. I'm currently utilizing the websocket module (which I've used successfully without TypeScript before) and facing difficulties with typing my variables ...

Retrieve the initial item from every sub-array within a master array

I'm working with arrays of arrays in TypeScript and I'd like to efficiently splice them to retrieve the first element of each sub-array. While it's not a particularly difficult task, I'm looking for a more succinct approach. Below is a ...

Having difficulty transmitting data through SocketIO in NodeJS

My current project involves sending streams of data through SocketIO sockets. I'm working on a Node TS application that will handle large files, so the standard Buffer object won't cut it. Here's the code I have so far: Client Side socket. ...

Assign a class to an Angular component's host element without any conditions

In my Angular project, I have a component where I need to apply a class unconditionally. To achieve this, the host property within the @Component decorator can be used: import { Component } from '@angular/core'; @Component({ selector: 'ap ...

Using Angular to dynamically access component properties

Seeking assistance with creating dynamic Tabs in TabView of PrimeNG. The components are displaying properly, but I am unsure how to access their properties. I am following the guidelines provided at https://angular.io/guide/dynamic-component-loader and us ...