pulse icon indicating copy to clipboard operation
pulse copied to clipboard

TypeError: Pulse is not a constructor

Open hakimscode opened this issue 1 year ago • 13 comments

I'm trying to use Pulse (migrated from Agenda). This is my code

import Pulse from '@pulsecron/pulse';

const mongoConnectionString = process.env.MONGO_URL || "mongodb://127.0.0.1:27018/pulse";
const pulse = new Pulse({ db: { address: mongoConnectionString } });

But I got an error that says:

TypeError: Pulse is not a constructor

Can someone explain why it happen and how to fix this? thanks

hakimscode avatar Jun 18 '24 08:06 hakimscode

Well, I figured it out. It turns out there is a mistake in import script. It should import like this import { Pulse } from '@pulsecron/pulse';

hakimscode avatar Jun 18 '24 09:06 hakimscode

Are you using JavaScript or Typescript?

code-xhyun avatar Jun 18 '24 23:06 code-xhyun

@code-xhyun I'm using Typescript

hakimscode avatar Jun 19 '24 02:06 hakimscode

@hakimscode I haven't encountered the same issue, so could you please provide me with your tsconfig file and the version of Pulse you're using?

code-xhyun avatar Jun 19 '24 02:06 code-xhyun

@code-xhyun Sure,

I'm using "@pulsecron/pulse": "^1.5.1"

this is my tsconfig

{
  "ts-node": {
    "esm": true,
    "experimentalSpecifierResolution": "node",
    "transpileOnly": true,
    "require": ["tsconfig-paths/register"]
  },
  "tsc-alias": {
    "resolveFullPaths": true
  },
  "compilerOptions": {
    "target": "ES2020",                                  
    "experimentalDecorators": true,                   
    "emitDecoratorMetadata": true,                    
    "module": "ESNext",                                
    "rootDir": "./src",                                  
    "moduleResolution": "Node",                     
    "baseUrl": ".",                                  
    "paths": {
      "@/*": ["./src/*"]
    },                                      
    "rootDirs": ["src"],                                   
    "typeRoots": ["node_modules/@types"],                             
    "types": ["node"],                                      
    "outDir": "./dist",                                   
    "esModuleInterop": true,                             
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "include": [ "src/**/*" ],
  "exclude": ["node_modules", "dist"]
}

hakimscode avatar Jun 19 '24 02:06 hakimscode

Thx : ) @hakimscode I will solve these and give you an answer as soon as possible.

code-xhyun avatar Jun 19 '24 07:06 code-xhyun

@hakimscode I tried the same configuration as you, but I did not encounter any issues. I will continue to investigate

image

code-xhyun avatar Jun 19 '24 09:06 code-xhyun

The same error for javascript.

AlexeyMoiseev avatar Jul 13 '24 21:07 AlexeyMoiseev

I am using like this and getting same error

const { Pulse } = require('@pulsecron/pulse');
const pulse = new Pulse();

virendrak-dev avatar Jul 14 '24 13:07 virendrak-dev

@AlexeyMoiseev @virendrak-dev I will check and inform you assuming that an issue occurs in JavaScript.

code-xhyun avatar Jul 15 '24 04:07 code-xhyun

import { Pulse } from '@pulsecron/pulse';
const pulse = new Pulse();

This works in my case. ESM, nodejs v20.15.1

AlexeyMoiseev avatar Jul 15 '24 13:07 AlexeyMoiseev

I am using like this and getting same error

const { Pulse } = require('@pulsecron/pulse');
const pulse = new Pulse();

in my case this works

while const Pulse = require('@pulsecron/pulse'); throw Pulse is not a constructor

@pulsecron/pulse: 1.6.3 node 20.10.0

aryomuzakki avatar Sep 11 '24 15:09 aryomuzakki

I am using like this and getting same error

const { Pulse } = require('@pulsecron/pulse');
const pulse = new Pulse();

in my case this works

while const Pulse = require('@pulsecron/pulse'); throw Pulse is not a constructor

@pulsecron/pulse: 1.6.3 node 20.10.0

Same.

zavan avatar Feb 18 '25 12:02 zavan