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

Force close process after build / prepare commands #193

Closed
enkot opened this issue Aug 31, 2023 · 17 comments · Fixed by nitrojs/nitro#2287
Closed

Force close process after build / prepare commands #193

enkot opened this issue Aug 31, 2023 · 17 comments · Fixed by nitrojs/nitro#2287
Labels
bug Something isn't working enhancement New feature or request

Comments

@enkot
Copy link

enkot commented Aug 31, 2023

Environment

  • Operating System: Linux
  • Node Version: v16.20.0
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.2
  • Nitro Version: 2.6.2
  • Package Manager: npm@9.4.2
  • Builder: -
  • User Config: modules, routeRules, hooks
  • Runtime Modules: @nuxt/devtools@0.8.2
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-c8qlr3?file=server%2Fplugins%2Ftest.ts

Describe the bug

If we add the page to routeRules (prerender: true) and start some timer/listener in the Nitro plugin, the process does not close after the build.
Also nitro.hooks.hook('close', () => {}) will never be called.

Additional context

It was working fine on Nuxt 3.6.5.

Temporary workaround (UPDATED):

export default defineNuxtConfig({
  hooks: {
    close: (nuxt) => {
      if (!nuxt.options._prepare)
        process.exit()
    }
  }
})

Logs

No response

@stackblitz
Copy link

stackblitz bot commented Aug 31, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Copy link
Member

cc: @pi0

@danielroe danielroe added the bug Something isn't working label Aug 31, 2023 — with Volta.net
@tobiasdiez
Copy link

Thanks for the workaround. It works well except that nuxi prepare no longer writes types. This can be resolved by slightly modifying the workaround to:

  hooks: {
    close: (nuxt) => {
      if (!nuxt.options._prepare) {
        process.exit()
      }
    },
  },

@danielroe danielroe transferred this issue from nuxt/nuxt Sep 16, 2023
@danielroe
Copy link
Member

~> #185

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2023
@tobiasdiez
Copy link

@danielroe I'm not sure if they are indeed the same issues, for me nuxi build hangs and but nuxi prepare works (my remark above concerning prepare was only about an issue with the hotfix)

@danielroe danielroe reopened this Sep 16, 2023
@danielroe
Copy link
Member

I'll leave it open for now then, pending further triage 👌

@enkot
Copy link
Author

enkot commented Sep 16, 2023

@danielroe This issue still exists on Nuxt 3.7.3 and has nothing to do with nuxi prepare.

@danielroe
Copy link
Member

Yes, the root issue in the linked issue is not actually related to the prepare command

@pi0 pi0 changed the title Nuxt doesn't exit the process after build Force close process after build / prepare commands Sep 16, 2023
@pi0 pi0 added the enhancement New feature or request label Sep 16, 2023
@pi0
Copy link
Member

pi0 commented Sep 16, 2023

This is a behavior change since we migrated to the new CLI infra. Previously we were "force closing" the process in case to prevent hanging handlers/listeners.

Modules should probably close their handler via close hook and we were silently doing this before.

I think we should add it back with also an explicit warning. But also only do it when using nuxi as CLI and not force exit for programmatic usage.

@davestewart
Copy link

Any movement on this? Does Nuxt 3.8 solve these issues?

@michalkuncio
Copy link

michalkuncio commented Oct 29, 2023

@davestewart unfortunately not. Tried it on 3.8 release day and the process is still hanging :(

@davestewart
Copy link

davestewart commented Oct 29, 2023

@pi0 this is a blocker for various modules including Nuxt Content Assets.

Projects which use these modules will be unable to update to the latest and greatest Nuxt.

Can you provide some comment or roadmap to resolution?

Would it be worth adding a close hook to the module as mentioned here?

Thanks

crearis added a commit to theaterpedia/theaterpedia-core that referenced this issue Jan 24, 2024
@santiagoaloi
Copy link

has this been resolved or do I need to use this workaround still?

@notthetup
Copy link

Nope. Seems like still unresolved even on the latest release. :(

Copy link
Member

For anyone still encountering this, a reminder that this typically occurs because of non-Nuxt code, typically within modules, but it can be anything that leaves something un-cleaned-up, such as a watcher.

I apologise for it taking so long, but I did eventually 🙈 take a look at Dave's module and prepared this PR, linked in case it's useful for anyone: davestewart/nuxt-content-assets#65.

I did look into it further and also found this issue with Nitro, which was likely also at play: nitrojs/nitro#2287

After that merges, I think we can close this issue, but if you're still encountering something like this in your project after that point, please open a new issue with a reproduction and I'll happily look into it further 🙏

@pi0
Copy link
Member

pi0 commented Mar 21, 2024

You can try the prerenderer fix using nightly release channel as @danielroe summarized this issue most of the times happens due to open handlers or watchers in modules.

@davestewart
Copy link

davestewart commented Mar 21, 2024

Great work (as usual) @danielroe!

I might also suggest to add some additional documentation around this.

Often as a module developer we're just focused on mainly getting something to work (i.e. the watch) and may either not think about the unwatch, or just not know enough about the wider context of the difference between build, dev, or in this case some change between Nuxt versions, which would blow up at some later date.

If – as a core developer – you suspect a footgun, please document to the lowest common denominator!

I can see that unwatch is documented, but in the bowels of developing a Nuxt plugin, triggered by Nitro, and leveraging unstorage, could there be any way to preempt showstoppers like this?

Maybe a gotchas or best practices for module developers in Nuxt docs?

Or, is the cycle of bugs > issues > debugging > repeating, etc just the way it is ?

tobiasdiez added a commit to JabRef/JabRefOnline that referenced this issue Aug 4, 2024
<!--
☝️ PR title should follow conventional commits
(https://conventionalcommits.org).
In particular, the title should start with one of the following types:

- docs: 📖 Documentation (updates to the documentation or readme)
- fix: 🐞 Bug fix (a non-breaking change that fixes an issue)
- feat: ✨ New feature/enhancement (a non-breaking change that adds
functionality or improves existing one)
- feat!/fix!: ⚠️ Breaking change (fix or feature that would cause
existing functionality to change)
- chore: 🧹 Chore (updates to the build process or auxiliary tools and
libraries)
-->

### 🔗 Linked issue

nuxt/cli#193

<!-- If it resolves an open issue, please link the issue here. For
example "Resolves #123" -->

### 📚 Description

The commit removes a workaround for a specific issue with Nuxt.js. The
issue has been resolved, so the workaround is no longer necessary.

<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants