Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Can't import module from typescript #23

Open
kuka-radovan opened this issue Sep 19, 2019 · 4 comments
Open

Can't import module from typescript #23

kuka-radovan opened this issue Sep 19, 2019 · 4 comments

Comments

@kuka-radovan
Copy link

I wanted to import this module to my typescript code. I tried to do it as follows:

import * as health from "@cloudnative/health-connect";

or I even tried

import health from "@cloudnative/health-connect";

But I cannot reach exported classes (e.g. HealthChecker). I am getting undefined from calling health.HealthChecker from first option or Module "@cloudnative/health-connect/index" has no default export. in case of second option.

The only solution I found is to import it like this

import { default as health } from "@cloudnative/health-connect";

but I personally don't like it and don't understand, why I have to rename default export that looks like it doesn't even has.

Do you have any solution or recommendation how to use this package in typescript? I am using typescript v 3.6.3.

@andrewhughes101
Copy link
Member

Hi @kuka-radovan there has been a new release recently and using the sample code below I was able to import the health-connect module using

 import * as health from '@cloudnative/health-connect'

and it seems to be working. My sample express app using health-connect in typescript is below. Let me know if you still encounter problems.

import express from 'express';
import * as health from '@cloudnative/health-connect';

const port = 3000;

const app = express();
let healthCheck = new health.HealthChecker();

const livePromise = () => new Promise<void>((resolve, _reject) => {
  setTimeout(resolve, 100, 'foo');
});

let liveCheck = new health.LivenessCheck("liveCheck", livePromise);
healthCheck.registerLivenessCheck(liveCheck);


app.use('/live', health.LivenessEndpoint(healthCheck))
app.get('/', (req, res) => {
  res.send('Hello!');
});
app.listen(port, () => {
  console.log("Listening on 3000");
});

@kuka-radovan
Copy link
Author

kuka-radovan commented Sep 30, 2019

Hi @andrewhughes101, thank you for your reply. I have the same result also with the new version. Please, can you provide your tsconfig.json file for that example? Thank you.

@andrewhughes101
Copy link
Member

Hi I'm using the same tsconfig.json as the cloud-health-connect module found here

@kuka-radovan
Copy link
Author

I don't understand, why I am getting health.HealthChecker is not a constructor error... My tsconfig.json looks the same. I have specific situation with that, I am trying to use that health-connect in library written in typescript, and after that I am using that lib in js code. TSC compiles without problems but node.js code throws that error when starting.

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

No branches or pull requests

2 participants