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

TypeError: Watchdog is not a constructor #18

Open
RobinGFT opened this issue Jun 7, 2018 · 1 comment
Open

TypeError: Watchdog is not a constructor #18

RobinGFT opened this issue Jun 7, 2018 · 1 comment
Labels

Comments

@RobinGFT
Copy link

RobinGFT commented Jun 7, 2018

Hi,
I wanted to test your module, but unexpectedly it won't function.
By creating a new instance of the class 'Watchdog' with

var Watchdog = require('watchdog');
const timeout = 5000;
const dog = new Watchdog(timeout);

I get the following Error: TypeError: Watchdog is not a constructor

Even by testing it with RunKit directly from the npm page (https://npm.runkit.com/watchdog) the error appears.

Maybe the problem appears cause of the mixing of typescript module and JavaScript Code...

@huan
Copy link
Owner

huan commented Jun 7, 2018

var Watchdog = require('watchdog') will not work because Watchdog is an ES6 module.

Your code should be able to work after any one the following changes:

  1. Module
var Watchdog = require('watchdog');
const timeout = 5000;
- const dog = new Watchdog(timeout);
+ const dog = new Watchdog.Watchdog(timeout);
  1. Deconstruct
- var Watchdog = require('watchdog');
+ const { Watchdog } = require('watchdog');
const timeout = 5000;
const dog = new Watchdog(timeout);
  1. ES6 Import
- var Watchdog = require('watchdog');
+ import { Watchdog } from 'watchdog';
const timeout = 5000;
const dog = new Watchdog(timeout);

RunKit

var watchdog = require("watchdog")
const timeout = 5000;
const dog = new watchdog.Watchdog(timeout);

@huan huan added the question label Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants