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!