Home

Issue: 1979

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

[issue link]

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.

This question is available on Nuxt.js community (#c1760)