DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error

在nuxt项目中添加了serverMiddleware,服务端中间件之后,打包爆出了这个警告,

   ╭──────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                      │
   │   ⚠ 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        │
   │                                                                                      │
   ╰──────────────────────────────────────────────────────────────────────────────────────╯

查看github,找到解决办法,
即:
原来是因为nuxt在打包过程中加载了serverMiddleware里的文件,出现了这个提示
解决办法,

1,去掉nuxt.config.js里的serverMiddleware配置

// nuxt.config.js
// serverMiddleware: [
//   '~/serverMiddleware/cache'
// ]

2,在nuxt.config.js里的modules里新加一个配置

// nuxt.config.js
modules: [
    '~/modules/api'
],

3,在项目的根目录下,新建一个modules文件夹

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

保存文件,运行npm run dev,可以正常运行,npm run build不会报错了。
github链接在这,如果不够详细的话,你去看看
https://github.com/nuxt/nuxt.js/issues/5669

你可能感兴趣的:(nuxt,Starting,with,N,Nuxt,Warning)