hywax / nuxt-cron

A Nuxt module for cron jobs in your app.
https://nuxt-cron.hywax.space
MIT License
53 stars 2 forks source link

[nuxt] [request error] [unhandled] [500] Cannot access 'nitroApp' before initialization #65

Open fdfrontdev opened 1 month ago

fdfrontdev commented 1 month ago

Version

"nuxt": "^3.11.2", "nuxt-cron": "^1.5.1",

Describe the problem

When using the command npm run dev, expect the nuxt server to run, instead got error

steps to reproduce:

  1. npm install nuxt-cron -D
  2. file : nuxt.config.ts
    export default defineNuxtConfig({
    modules: ['nuxt-cron'],
    cron: {
    runOnInit: true,
    timeZone: 'Asia/Kuala_Lumpur',
    jobsDir: 'cron'
    }
    })

    4.file : server/cron/job.ts

    
    import { defineCronHandler } from '#nuxt/cron'

export default defineCronHandler('0 8 *', () => { try { console.log('I run every 8 am') } catch (error) { throw createError({ statusCode: 404, statusMessage: 'Fail to run scheduler' }) } })



5. npm run dev
6. expected result: nuxt server running
7. actual result : [nuxt] [request error] [unhandled] [500] Cannot access 'nitroApp' before initialization

### Additional info

![image](https://github.com/hywax/nuxt-cron/assets/147123307/1858cd9f-2ddf-43aa-a412-3df4c9febd20)
hywax-assistant commented 1 month ago

👋 @fdfrontdev Thanks for opening your first issue here! To help make it easier for us to investigate your issue, please follow the contributing guidelines.

If you like this project, please ⭐ star our repo.