Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid npm package dependencies #233

Closed
konraddysput opened this issue Jun 11, 2019 · 10 comments
Closed

Invalid npm package dependencies #233

konraddysput opened this issue Jun 11, 2019 · 10 comments

Comments

@konraddysput
Copy link

I'm submitting a...


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When I download latest version of libraries via npm:

$ npm install --save @nestjs/terminus @godaddy/terminus

and I'm trying to use healtchecks like below:

import {
  TerminusEndpoint,
  TerminusOptionsFactory,
  DNSHealthIndicator,
  TypeOrmHealthIndicator,
  TerminusModuleOptions,
  MemoryHealthIndicator,
  DiskHealthIndicator,
} from '@nestjs/terminus';
import { Injectable } from '@nestjs/common';

@Injectable()
export class HealthCheck implements TerminusOptionsFactory {
  constructor(
    private readonly _dns: DNSHealthIndicator,
    private readonly _typeorm: TypeOrmHealthIndicator,
    private readonly _memoryHealthIndicator: MemoryHealthIndicator,
    private readonly _diskHealthIndicator: DiskHealthIndicator,
  ) {}

  public createTerminusOptions(): TerminusModuleOptions {
    const healthEndpoint: TerminusEndpoint = {
      url: '/health',
      healthIndicators: [
        async () => this._dns.pingCheck('google', 'https://google.com'),
        async () => this._typeorm.pingCheck('database', { timeout: 1500 }),
        async () =>
          this._diskHealthIndicator.checkStorage('storage', { thresholdPercent: 0.5, path: '/' }),
        async () => this._memoryHealthIndicator.checkRSS('rss', 500 * 1024 * 1024),
        async () => this._memoryHealthIndicator.checkHeap('heap', 100 * 1024 * 1024),
        async () => this._typeorm.pingCheck('database', { timeout: 1500 }),
      ],
    };
    return {
      endpoints: [healthEndpoint],
    };
  }
}

I'm receiving build errors. Please check image below:
image

I tried to install manually packages, but it still doesn't work.

Expected behavior

After $ npm install --save @nestjs/terminus @godaddy/terminus I expect to have every needed dependency, or detailed instruction what I should do if I want to use providers from official doc:
https://docs.nestjs.com/recipes/terminus

Minimal reproduction of the problem with instructions

$ npm install --save @nestjs/terminus @godaddy/terminus
$ tsc build

Environment

"@godaddy/terminus": "^4.1.2",
"@nestjs/terminus": "^6.3.1",
NodeJS: v10.16.0
Windows 10

@BrunnerLivio
Copy link
Member

BrunnerLivio commented Jun 11, 2019

I tried it out myself and it works with a clean setup:

nest new terminus-test
cd terminus-test
npm i -s @nestjs/terminus @godaddy/terminus

I have added 1:1 your code and received the following result, which is expected at the current state of 6.3.x:

{
  "status": "error",
  "error": {
    "rss": {
      "status": "up"
    },
    "heap": {
      "status": "up"
    },
    "storage": {
      "status": "up"
    },
    "google": {
      "status": "up"
    },
    "database": {
      "status": "down",
      "message": "Connection provider not found in application context"
    }
  },
  "details": {
    "rss": {
      "status": "up"
    },
    "heap": {
      "status": "up"
    },
    "storage": {
      "status": "up"
    },
    "google": {
      "status": "up"
    },
    "database": {
      "status": "down",
      "message": "Connection provider not found in application context"
    }
  }
}

Could you share a minimal reproduction of your repo?

@konraddysput
Copy link
Author

@BrunnerLivio are you using typescript?

@BrunnerLivio
Copy link
Member

@konraddysput yes

➜ tsc -v
Version 3.2.2

➜ node -v   
v12.4.0

@konraddysput
Copy link
Author

You have right - I started project from the beginning like you did and I found what was a problem. My tsconfig:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": { "*": ["types/*"] },
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "./dist/",
    "incremental": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "allowSyntheticDefaultImports": true
  },
  "exclude": ["./tests", "./dist", "./node_modules", "dist", "**/*spec.ts"]
}

Do you see anything wrong here?

@konraddysput
Copy link
Author

OK, I see a problem is with two typescript flags:

"strict": true,
"noImplicitAny": true,

@BrunnerLivio do you know why I cannot use them with your library? Actually I need to use them in my code.

@BrunnerLivio
Copy link
Member

BrunnerLivio commented Jun 17, 2019

@konraddysput sorry for the late reply.

I was able to reproduce your error. I worked around this problem by using my custom types. This is not sustainable, so I will create a PR to the library itself to support the typings in strict mode. You can follow the discussion here: Alex-D/check-disk-space#3

If you want to workaround this in your project, you have to set the setting in your tsconfig.json

{
  "compilerOptions": {
    "paths": { "*": ["types/*"] }
  }
}

and add the types folder with check-disk-space.d.ts

mkdir types
cat <<EOT >> types/check-disk-space.d.ts
import { totalmem } from 'os';

export = index;
declare function index(
  directoryPath: string,
): Promise<{ free: number; size: number }>;
declare namespace index {
  class InvalidPathError {
    constructor(message: any);
    name: any;
    message: any;
  }
  class NoMatchError {
    constructor(message: any);
    name: any;
    message: any;
  }
  function getFirstExistingParentPath(directoryPath: any): any;
}

EOT

@konraddysput
Copy link
Author

Thanks @BrunnerLivio :) I will wait for new version then.

@konraddysput
Copy link
Author

Hey @BrunnerLivio

Today I had a chance to update package add check if types works with strict mode. Unfortunately, TypeScript still complain about missing types.

I had a chance to add check-disk-space types definition to project, but it still doesn't work. Now I have problem with mongoose.health.d.ts

Thanks!

@konraddysput konraddysput reopened this Jul 4, 2019
@BrunnerLivio
Copy link
Member

I think it would make sense if you would use skipLibCheck - or is anything against this option?

{
  "compilerOptions": {
    "skipLibCheck": true
    ...
  }
}

@BrunnerLivio
Copy link
Member

Screw skipLibCheck - fixed with 6.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants