pulsecron / pulse

The modern MongoDB-powered job scheduler library for Node.js
https://pulsecron.com
MIT License
59 stars 4 forks source link

TypeError: Pulse is not a constructor #38

Open hakimscode opened 4 weeks ago

hakimscode commented 4 weeks ago

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 commented 4 weeks ago

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';

code-xhyun commented 4 weeks ago

Are you using JavaScript or Typescript?

hakimscode commented 4 weeks ago

@code-xhyun I'm using Typescript

code-xhyun commented 4 weeks ago

@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?

hakimscode commented 4 weeks ago

@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"]
}
code-xhyun commented 4 weeks ago

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

code-xhyun commented 4 weeks ago

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

image

AlexeyMoiseev commented 3 days ago

The same error for javascript.

virendrak-dev commented 3 days ago

I am using like this and getting same error

const { Pulse } = require('@pulsecron/pulse');
const pulse = new Pulse();
code-xhyun commented 2 days ago

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

AlexeyMoiseev commented 2 days ago
import { Pulse } from '@pulsecron/pulse';
const pulse = new Pulse();

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