nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module crashes site

invisor opened this issue · comments

Hi. Every time when I adding module to module section is crashing my site. I got this error
Cannot GET /
Any links from my site return this error. How to fix this? What additional info do you need?

Works fine for me. Any specific info about your issue?

Hi, i'm dealing with that same problem.

In the server log it prints:

node_modules/@nuxtjs/redirect-module/lib/module.js:1 (function (exports, require, module, __filename, __dirname) { export default async function nuxtRedirect(moduleOptions) { ^^^^^^ SyntaxError: Unexpected token export

i got it working by using a different export method.

nuxtRedirect = async function(moduleOptions) {
  if (typeof moduleOptions === 'function') {
    moduleOptions = await moduleOptions()
  }
  if (typeof this.options.redirect === 'function') {
    this.options.redirect = await this.options.redirect()
  }

  const initialRules = Object.assign([], this.options.redirect, moduleOptions)

  // Transform each "from" value to a RegExp for later test
  const regExpRules = initialRules.map(o => Object.assign(o, { from: new RegExp(o.from) }))
  const middleware = require('./middleware.js')(regExpRules)

  this.addServerMiddleware(middleware)
}

module.exports = nuxtRedirect

@JesperHonders please make sure you are using Nuxt 2 and upwards.

@invisor more info is needed, ideally a reproduction repo.