nitrojs / nitrojs/nitro

Scheduled tasks executed twice if scheduled in a layer

Open
#4,155 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug nuxt v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the Nuxt StackBlitz reproduction and inspect the generated .nuxt/dev/index.mjs, especially the scheduledTasks array. Compare the project and layers/base/nuxt.config.ts definitions, then trace the configuration merge that produces duplicate task names. Done means the scheduled task logs once per minute when defined in a layer.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, nuxt, typescript, vite
Domain
backend, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.