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

Created on 8 May 2019  ยท  14Comments  ยท  Source: nuxt/nuxt.js

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?

This bug report is available on Nuxt community (#c9167)
bug-report

Most helpful comment

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).

All 14 comments

Hard to tell w/o the actual code :wink:

@manniL
repository in private, so can't give source code ๐Ÿ˜ข
but i found nuxt warning occuured when mongose.connect in serverMiddleware.

in nuxt.config.js

serverMiddleware: [
   '~/serverMiddleware/index.js'
]

in ~/serverMiddleware/index.js

const app = express()

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

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

how can i handle it?

it is the better case changing serverMiddleware to using Nuxt.js programmatically?
but i think it is more complex way to solve them..(because loosing serverMiddleware's pros)

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).

@Atinux thanks a lot!!

I'am building a nuxt & electron & express application.
Eveverything is ok when i build & start an application on web.
But when i use electron-builder, it works on developer mode, but not on production.

I think, i need to add a new parameter, etc: || this.options.ELECTRON. But what is it ?

 if (this.options.dev || this.options._start  || etc. this.options.ELECTRON) {
   this.addServerMiddleware('~/server/index.js')
}

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

I was able to reproduce an issue when running nuxt build locally without HardSourceWebpackPlugin enabled so I guess it's not related

same problem here. I also used recently HardSourceWebpackPlugin

when i use parallel in build ๏ผŒi get this issue

@fpl1104 Same here. According to nuxt doc, parallel is an โš ๏ธ Experimental feature i think.

Is there any way to fix it by not disabling parallel option?

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

@Atinux please, reopen this issue since it can be reproduced with parralel:true and it's still occurring in 2.13.1

Could your provide a reproduction and mention me please?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  ยท  3Comments

gary149 picture gary149  ยท  3Comments

mikekidder picture mikekidder  ยท  3Comments

vadimsg picture vadimsg  ยท  3Comments

o-alexandrov picture o-alexandrov  ยท  3Comments