Static GitHub Issues

[1979] Can't generate when using middleware to check user agent.

prev: Feature Request: Static Export
next: Customize server console output.

Hi,

When I use this (same as in the middleware example in the docs)....

export default function (context) {
  context.userAgent = process.server ? context.req.headers['user-agent'] : navigator.userAgent
}

... and then nuxt generate, the generation fails with this error:

 Error: ENOENT: no such file or directory, lstat 'C:\Program Files (x86)\Ampps\www\2\dist\index.html'
    at Error (native)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'C:\\Program Files (x86)\\Ampps\\www\\2\\dist\\index.html' }

Why is this and how can I fix it? My full middleware function looks like this

export default function (context) {
  context.userAgent = process.server ? context.req.headers['user-agent'] : navigator.userAgent
  context.isMoble = /mobile/i.test(context.userAgent)
  context.store.commit('setMobile', context.isMobile)
}

I also tried this: https://github.com/awronski/nuxtjs-examples/blob/master/mobile-desktop-with-store/store/index.js with the same result.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1760">#c1760</a>)</em></sub></div>