I am facing an issue with my nestjs app where I am trying to incorporate winston as a logger service. However, this implementation is causing my app to break and I am unsure how to resolve or revert this issue. I have attempted to uninstall the winston packages, delete node_modules folder, and reinstall npm packages, but none of these solutions have worked.
node -v: v11.15.
nest -v: 7.1.5
yarn -v: 1.22.4
npm -v: 6.14.5
The error message I am encountering:
[11:37:19 AM] Found 0 errors. Watching for file changes.
internal/modules/cjs/loader.js:670
throw err;
^
Error: Cannot find module './app.module'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
at Function.Module._load (internal/modules/cjs/loader.js:591:27)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (/Users/dtmirror/app-api/dist/src/main.js:4:22)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
List of installed packages:
npm i winston
Here is the code for LoggerService:
import * as winston from 'winston';
import { LoggerOptions } from 'winston';
export class LoggerService {
private logger;
public static loggerOptions: LoggerOptions = {
transports: [
new winston.transports.File({ filename: 'app.log' })
]
}
constructor(private context: string, transport?) {
this.logger = (winston as any).createLogger(LoggerService.loggerOptions);
}
log(message: string): void {
const currentDate = new Date();
this.logger.info(message, {
timestamp: currentDate.toISOString(),
context: this.context,
})
}
}
Snippet from main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { LoggerService } from '../logger.service'; // <-- this breaks everything
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
Whenever I try running yarn start:dev
, the entire application crashes in this state...