angularservicemonorepotypeofnomachine-nx

Property 'trace' does not exist on type 'typeof NxWelcomeService'.ts(2339)


I am migrating my project to Nx Monorepo and it happens that libraries that worked fine in my project outside of Nx do not recognize public methods here. It doesn't happen only with libraries, I have created a simple component and service to test and it throws the same error This is the code nx-welcome.component.ts:

import { Component, OnInit } from '@angular/core';
import { NxWelcomeService } from './nx-welcome.service' 

@Component({
  selector: 'linde-tgv-nx-welcome',
  templateUrl: './nx-welcome.component.html',
  styles: []
})
export class NxWelcomeComponent implements OnInit {
  constructor() {
  };
  private logger = NxWelcomeService
  
  ngOnInit(): void {
    this.logger.trace('checklist-app - NxWelcomeComponent')
  }
}

nx-welcome.component.ts:

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class NxWelcomeService {

  constructor() { }
  
  public trace(message :string) {console.log(message)}
}

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@linde-tgv/generated/linde-api-types": [
        "libs/generated/linde-api-types/src/index.ts"
      ],
      "@tgv/logger": ["libs/tgv-logger/src/index.ts"],
      "my-lib": [
        "dist/my-lib/my-lib",
        "dist/my-lib"
      ]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    },
    {
      "path": "./tsconfig.editor.json"
    }
  ],
  "compilerOptions": {
    "target": "es2020",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

Solution

  • The problem was not with NX. I had defined

    private logger = NxWelcomeService
    

    rather than

    constructor(private logger: NxWelcomeService)