Troubleshooting the ineffectiveness of Relative paths, baseUrl, and paths in Ionic2 with Angular2

I've been doing some research on similar forums but I haven't been able to find a solution yet. There must be a small step that I am overlooking.

My objective is to achieve:

import { Logger } from 'logging'

instead of

import { Logger } from '../../modules/logging'

This is how my tsconfig file looks like:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "baseUrl": ".",
    "paths":{
      "*":[
        "src/app/*",
        "node_modules/*"
      ]
    }
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

The structure of my folders looks something like this

src
--- app
------- logging
--------------- index.ts (contains exports for the provider and the ngModule)
--------------- logger.provider.ts (contains an injectable provider)
--------------- logging.module.ts (contains the ngModule)
--- app.module.ts

The index file includes the following:

export { LoggingModule } from './logging.module';
export { LoggerProvider } from './logger.provider';

I have omitted some files from the folder structure. The app.module.ts serves as my main class where I am attempting to import the 'logging' module. Visual Studio Code does not indicate any issues with my imports.

//import { FIREBASE_CONFIG } from 'configs';
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { AngularFireModule } from "angularfire2";
import { LoggingModule } from 'logging'; 
import { PostsModule } from 'posts';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    PostsModule,
    LoggingModule
    //AngularFireModule.initializeApp(FIREBASE_CONFIG),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}

While VSC does not flag any errors, when I run the app in the browser, I encounter the following error:

Error: Cannot find module "logging"
    at Object.<anonymous> (http://localhost:8100/build/main.js:82202:7)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:105047:70)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at http://localhost:8100/build/main.js:66:18
    at http://localhost:8100/build/main.js:69:10

I am determined to avoid reverting back to lengthy relative paths because it is both cumbersome and would complicate refactoring as the application expands.

Thank you!

Answer №1

Could the problem be with the moduleResolution setting, which is currently set to node? Try changing it to classic and check if the issue gets resolved.

"compilerOptions": {
    "moduleResolution": "classic"

You may want to refer to this link for more insights on the matter. Hopefully, this will help resolve the error.

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

An issue has occurred: Failure to execute spawnSync PATH/target/node/node ENOENTNGCC. Please refer to the

Attempting to initiate my angular project using ./mvnw is resulting in an error when the build runs ng build --configuration development. The error message thrown reads as follows: Generating browser application bundles (phase: setup)... [INFO] /home/use ...

Path for WebStorm file watcher's output

I'm in the process of setting up a Typescript project in WebStorm, where I want the files to be transpiled into a dist folder. This is my current project folder structure: projectroot/src/subfolder/subfolder/index.ts What I aim for is to have the f ...

Customize the form using a custom component in react-hook-form: setting a default value

I have been learning ReactJS + TypeScript for 3 months now. Recently, I have a question about using react-hook-form (v7) to edit a form. I want to integrate my custom component into the form and I managed to do it on my own! Here is a snippet of my form p ...

A generalized function that provides IEntity[E][S] as its return type, delving into two levels of

I've encountered a compilation/type error while attempting to implement something similar to the code snippet below. interface IEntityLookup { [Entity.PERSON]: IPersonLookup [Entity.COMPANY]: ICompanyLookup } interface ISubEntity { [Entit ...

Is using instanceof the most effective method to verify type in Angular?

When working with the model, we import Type1 and Type2. Using the TypeComp variable which is a union of Type1 and Type2. import { Type1, Type2 } from '.'; export type TypeComp = Type1 | Type2; In the some.component.ts file, the selectedData$ obs ...

Angular 2 displayed a vibrant HTML page component

In my project, there is an Isotope Component that I want to keep protected from unauthorized access. If a user is not logged in and tries to navigate directly to the Isotope page by entering a specific route like: http://localhost:4200/register and then ...

Tips for denoting unnecessary non-null assertions in Typescript

Incorporated this wrapper (source) into the project I'm currently working on: export function expectToBeDefined<T>( arg: T, ): asserts arg is Exclude<T, undefined> { expect(arg).toBeDefined(); } The objective is to eliminate the usage ...

Using Ionic 4 with Angular to set the root of the application and control navigation with the back button

There has been a consensus to avoid using NavController in Ionic 4 and instead utilize Angular's router. For those not utilizing lazy loading, routes are set up like this: { path: '', component: WalkthroughComponent }, { path: 'login& ...

Splitting files with Webpack generates dynamic chunk files

Anticipating to only have two distinct chunks named vendors and commons, webpack unexpectedly generates a new chunk file for specific entries with a delimiter. optimization: { splitChunks: { chunks: 'all', cacheGroups: { ...

Integrating a title field into every p-column with ng-template

I am exploring ng-templates for the first time. I have managed to customize each column to display names accurately, but I am encountering an issue. I would like to incorporate a title field in order to show a tooltip with the full name when hovering over ...

Angular V8 build is not functioning correctly because it is broken

Unexpectedly, our ng build task in the VSTS pipeline is no longer functioning. Initially, the issue only appeared on VSTS, but when I cleared and reinstalled the node_modules on my local machine, I was able to replicate the problem. This leads me to believ ...

Locate items within a nested array of objects

I need to extract a specific object from a JSON array with nested objects by using the key name. I've attempted various methods but haven't found a generic solution yet. let data = {"role":"http://www.icai.org/xbrl/taxonomy/role/in ...

Exploring the Use of ng-content in Angular for Displaying Secondary Content

A custom Angular component has been developed to project provided content: import { Component, Input } from '@angular/core'; @Component({ selector: 'app-box', template: '<ng-content select="[body]"></ng-cont ...

The property 'setParentKeyForNodeData' is not found in the 'Model' type. Perhaps you meant to use 'setCategoryForNodeData'?

As I work with gojs and utilize an organizational chart, I have encountered a problem with one of the context menus. Specifically, when selecting "Remove Role", I receive an error message stating Property 'setParentKeyForNodeData' does not exist ...

Is there a way to adjust the opacity of a background image within a div?

I have a lineup of elements which I showcase in a grid format, here's how it appears: https://i.stack.imgur.com/JLCei.png Each element represents a part. The small pictures are essentially background-images that I dynamically set within my html. Up ...

Combining the JSON code coverage reports generated by both Cypress and Karma does not yield an accurate outcome

In my angular project, I am testing it using the built-in unit testing tool (karma) and Cypress. My goal is to combine the code coverage reports from both tests. I have successfully set up the coverage configurations and merged the outputs using `nyc merg ...

Angular 5 - Creating a dynamic function that generates a different dynamic function

One of my latest projects involved creating a versatile function that generates switch-case statements dynamically. export function generateReducer(initialState, reducerName: ReducerName, adapter: EntityAdapter<any>): (state, initialState) => ISt ...

Is there a way to implement jquery (or other external libraries) within Typescript?

Currently, I am diving into Typescript to enhance my skills and knowledge. For a project that is being served with Flask and edited in VSCode, I am looking to convert the existing JavaScript code to Typescript. The main reason for this switch is to leverag ...

Updating an object property within an array in Angular Typescript does not reflect changes in the view

I am currently delving into Typescript and Angular, and I have encountered an issue where my view does not update when I try to modify a value in an array that is assigned to an object I defined. I have a feeling that it might be related to the context b ...

Using "http2" in Angular 7 is imperative for improving network performance and enhancing speed

Seeking to implement http2 on the client side of my Angular project. const http2 = require("http2"); const client = http2.connect("http://localhost:8443"); const req = client.request({ ":path": "/" }); Encountered an error when attempting an http2 r ...