TypeError: Pulse is not a constructor
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
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';
Are you using JavaScript or Typescript?
@code-xhyun I'm using Typescript
@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 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"]
}
Thx : ) @hakimscode I will solve these and give you an answer as soon as possible.
@hakimscode I tried the same configuration as you, but I did not encounter any issues. I will continue to investigate
The same error for javascript.
I am using like this and getting same error
const { Pulse } = require('@pulsecron/pulse');
const pulse = new Pulse();
@AlexeyMoiseev @virendrak-dev I will check and inform you assuming that an issue occurs in JavaScript.
import { Pulse } from '@pulsecron/pulse';
const pulse = new Pulse();
This works in my case. ESM, nodejs v20.15.1
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
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.