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

Module '"cron"' declares 'CronJob' locally #906

Closed
decoderid opened this issue Nov 4, 2024 · 4 comments
Closed

Module '"cron"' declares 'CronJob' locally #906

decoderid opened this issue Nov 4, 2024 · 4 comments
Labels
type:bug Bug reports and bug fixes

Comments

@decoderid
Copy link

Description

According to the documentation below, to perform the import in the following way:

import { CronJob } from 'cron';

However, an error occurs that results in:

Module '"cron"' declares 'CronJob' locally.

To perform the correct import in TypeScript, use:

import { CronJob } from 'cron/dist';

Expected Behavior

import { CronJob } from 'cron';

Actual Behavior

import { CronJob } from 'cron/dist';

Possible Fix

No response

Steps to Reproduce

import { CronJob } from 'cron';

CronJob.from({
    cronTime: '* * * * * *',
    onTick: () => {
        console.log('Testing Cron')
    },
    start: true
})

Context

no

Your Environment

  • cron version: 3.1.8
  • NodeJS version: 21.7.2
  • Operating System and version: Windows 11
  • TypeScript version: 5.6.3
@intcreator
Copy link
Collaborator

intcreator commented Nov 4, 2024

I can duplicate this issue using Node v20 and v21, but it works fine in Node v22 and v23. it's possible that a recent package update inadvertently broke support for Node <v22. will look into it

update: I tested cron versions 3.1.8, 3.1.7, 3.1.6, and 3.1.5. all have the same issue, so this has been here for a while

update 2: my bad, I was actually getting a different error which was a local configuration issue. I can't duplicate this.

where are you getting the error, inside a .ts file that you're trying to compile? is the error in a code editor or TypeScript compiler output? or something else?

@decoderid
Copy link
Author

decoderid commented Nov 4, 2024

I can duplicate this issue using Node v20 and v21, but it works fine in Node v22 and v23. it's possible that a recent package update inadvertently broke support for Node <v22. will look into it

update: I tested cron versions 3.1.8, 3.1.7, 3.1.6, and 3.1.5. all have the same issue, so this has been here for a while

update 2: my bad, I was actually getting a different error which was a local configuration issue. I can't duplicate this.

where are you getting the error, inside a .ts file that you're trying to compile? is the error in a code editor or TypeScript compiler output? or something else?

The error appears in both the editor and the compiler output.

Editor

{F9DC21A1-0CB5-46E7-99C8-A2AB250CEABF}

Output

{E82F1F9E-692E-4F58-BB71-14A6F5FD73C4}

Update to cron/dist everything is fine

{BFDE77FA-C6A4-4C93-83D0-0C5394E769A8}

{68ACA71A-B0D5-4807-B9D3-009445E158A1}

package.json

{
  "devDependencies": {
    "@types/mongoose": "^5.11.97",
    "@types/winston": "^2.4.4",
    "@typescript-eslint/eslint-plugin": "^8.12.2",
    "@typescript-eslint/parser": "^8.12.2",
    "copyfiles": "^2.4.1",
    "eslint": "^9.13.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^5.2.1",
    "eslint-plugin-promise": "^7.1.0",
    "prettier": "^3.3.3",
    "rimraf": "^6.0.1",
    "ts-node": "^10.9.2",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.6.3"
  },
  "dependencies": {
    "@types/luxon": "^3.4.2",
    "@types/radius": "^0.0.33",
    "cron": "^3.1.8",
    "dotenv": "^16.4.5",
    "luxon": "^3.5.0",
    "mongoose": "^8.7.3",
    "mongoose-paginate-v2": "^1.8.5",
    "radius": "^1.1.4",
    "winston": "^3.15.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2016",
    "module": "CommonJS",
    "rootDir": "./src",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "noImplicitAny": false,
    "baseUrl": "./src",
    "removeComments": true,
    "sourceMap": false
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "dist"]
}

@sheerlox
Copy link
Collaborator

sheerlox commented Nov 4, 2024

Thanks for the report, it should be fixed by #908.

This issue will be updated once the PR is merged and a new version is released. Feel free to re-open it then if the problem is still occurring on the latest version.

@sheerlox sheerlox closed this as completed Nov 4, 2024
intcreator pushed a commit that referenced this issue Nov 4, 2024
## Description

See related issue.

## Related Issue

#906

## Motivation and Context

## How Has This Been Tested?

Untested, just followed the TypeScript doc:
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package

## Screenshots (if appropriate):

## Types of changes

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

- [X] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [X] All new and existing tests passed.
- [ ] If my change introduces a breaking change, I have added a `!`
after the type/scope in the title (see the Conventional Commits
standard).
@sheerlox
Copy link
Collaborator

sheerlox commented Nov 4, 2024

🎉 This PR is included in version 3.1.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug reports and bug fixes
Projects
None yet
Development

No branches or pull requests

3 participants