Skip to content

Scheduled tasks executed twice if scheduled in a layer #4155

@maxirozay

Description

@maxirozay

Environment

Operating system Linux 5.15.153.1-microsoft-standard-WSL2
CPU unknown (12 cores)
Node.js version v24.12.0
nuxt/cli version 3.34.0
Package manager pnpm@10.12.1
Nuxt version 4.4.2
Nitro version 2.13.1
Builder vite@7.3.1
Config app, compatibilityDate, css, devtools, extends, i18n, routeRules, runtimeConfig
Modules -

Reproduction

Nuxt repoduction:
https://stackblitz.com/edit/github-pupvohms?file=layers%2Fbase%2Fnuxt.config.ts
Just run it and check the logs. Every minute there will be 2 new logs from a single task.

Nitro reproduction:
I tried to recreate it with only nitro but no matter how I define the task it says "Scheduled task test is not defined!"
https://stackblitz.com/edit/github-bww96yvy?file=layers%2Fbase%2Fnitro.config.ts

Describe the bug

If a task is scheduled in a layer it is executed twice per execution.

If I put

   scheduledTasks: {
     '* * * * *': ['test'],
   },

in the nitro config from the project it is executed once per minute if I put it in the nitro config from the layer it is executed twice per minute.

It looks like when the configs are merged the tasks are duplicated. You can see in .nuxt/dev/index.mjs the tasks are defined with const scheduledTasks = [{"cron":"* * * * *","tasks":["test","test"]}];

Additional context

@pi0 as requested I report this issue in the nitro repo with a nitro reproduction except that in my reproduction nitro doesn't seem to see my task so I left the nuxt reproduction to see the bug but I guess you can easily fix the issue with my nitro reproduction.

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions