nuxt: How do i fix Nuxt Warning 'nuxt build finished but did not exit after 5s'?

Version

v2.6.3

Reproduction link

https://nuxtjs.org

Steps to reproduce

i thinks it happen when migrate to nuxt 2.x version from any version

What is expected ?

not appearing ⚠ Nuxt Warning

What is actually happening?

╭───────────────────────────╮ │ │ │ ⚠ Nuxt Warning │ │ │ │ The command ‘nuxt build’ finished but did not exit after 5s │
│ │ │ This is most likely not caused by a bug in Nuxt.js │
│ │
│ Make sure to cleanup all timers and listeners you or your │ │ plugins/modules start. │ │ Nuxt.js will now force exit │ │ │ │ DeprecationWarning: Starting with Nuxt version 3 this will . │ │ be a fatal error │ │
╰───────────────────────────╯

Additional comments?

i have no idea from warning message Make sure to cleanup all timers and listeners you or your plugins/modules start.

i already check out pluggins and module directory i wrote before, but there’s no timer/interval expressions.

how can i found cause of this things?

<div align="right">This bug report is available on Nuxt community (#c9167)</div>

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (3 by maintainers)

Most upvoted comments

The issues comes because we actually import the serverMiddleware when running nuxt build.

What you can do instead is to create a module for it @highalps

~/nuxt.config.js:

export default {
  modules: ['~/modules/api']
}

~/modules/api/index.js:

module.exports = function (moduleOptions) {
  // Add middleware only with `nuxt dev` or `nuxt start`
  if (this.options.dev || this.options._start) {
    this.addServerMiddleware('~/api/')
  }
}

~/api/index.js:

const express = require('express')
const app = express()

mongoose.connect('....') // it is problem

app.use('/', require('.......'))

module.exports = { path: '/api', handler: app }

You can learn more on https://nuxtjs.org/guide/modules

We are talking with the core team to work on a solution to avoid includes the serverMiddleware when running nuxt build.

But mostly, we will soon have Nuxt services allowing to create your API in your Nuxt app without having to add serverMiddleware (better for perf & memory management + hot reloading).

Hard to tell w/o the actual code 😉

@Atinux Just create new nuxt app and add:

build: {
  parallel: true,
  cache: true,
  hardSource: true,
}

After the second build try you will get the same warning

UPD: Turning off parallel disables this warning

when i use parallel in build ,i get this issue

I started getting this issue once I enabled HardSourceWebpackPlugin in production build

@arnabrahman Obviously yes, but how can I fix it?