jurassicjs / nuxt-scheduler

Create scheduled jobs with human readable time settings
211 stars 6 forks source link

Importing useSheduler thwowing an error : #10

Closed lewismunene020 closed 12 months ago

lewismunene020 commented 1 year ago

I am using Nuxt Schduler but i keep getting this error. What might be wrong?

 ERROR  Failed to resolve import "#scheduler" from "plugins/cronScheduler.ts". Does the file exist?

Here is my code

import { useScheduler } from "#scheduler";

export default defineNitroPlugin(() => {
  startScheduler();
});

function startScheduler() {
  const scheduler = useScheduler();

  scheduler
    .run(() => {
      console.log("=====>cool beans! I run once a second! 😀");
    })
    .everySeconds(4);

  // create as many tasks as you want here
}
sisou commented 12 months ago

After you run nuxt dev once, it generates the types for it, and will resolve the types correctly from then on. At least it did for me.

rohrig commented 12 months ago

nuxt-scheduler only works on the server. try ~/server/plugins/cronScheduler.ts