1

I want to enable github pages for deployment in nuxt. Following the docs though I cannot get it correct in the conf file.

This is what they note to add in the file. I have added it in several locations in the file but each time it errors.

/* nuxt.config.js */
// only add `router.base = '/<repository-name>/'` if `DEPLOY_ENV` is `GH_PAGES`
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
  router: {
    base: '/<repository-name>/'
  }
} : {}

export default {
  ...routerBase
}

My code for exports.

module.exports = {
  mode: 'spa',
  const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ?
      {router: {base: '/mortalcatalyst.github.io/'}} :
      {} export default {router: {base: '/mortalcatalyst.github.io/'}},
  /*
   ** Headers of the page
   */
  head: {
    title: pkg.name,
    meta: [
      {charset: 'utf-8'},
      {name: 'viewport', content: 'width=device-width, initial-scale=1'},
      {hid: 'description', name: 'description', content: pkg.description}
    ],
    link: [{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}]
  }, # rest of config (standard)

Error

 FATAL  Invalid or unexpected token                                  22:06:37

  const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
  ^

  SyntaxError: Invalid or unexpected token
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)


   ╭──────────────────────────────────────────────╮
   │                                              │
   │   ✖ Nuxt Fatal Error                         │
   │                                              │
   │   SyntaxError: Invalid or unexpected token   │
   │                                              │
   ╰──────────────────────────────────────────────╯

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] generate: `nuxt generate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] generate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

1 Answer 1

2

You have a malformed JS object at the 3th line:

module.exports = {
  mode: 'spa',
  const routerBase = ...  // it must be a "key: value" not a "const" declaration

So you can replace by an external declaration, then add variable with spread operator ... on export default:

const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ?
  {router: {base: '/mortalcatalyst.github.io/'}} :
  {}

export default {
  ...routerBase,
  /*
   ** Headers of the page
   */
  head: {

  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I still receive same error though. It shows the same syntax error in editor as well. I changed to look like your code but it seems the same to me.
module.exports = { mode: 'spa', const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {router: {base: '/mortalcatalyst.github.io/'}} : {} export default { router: {base: '/mortalcatalyst.github.io/'}, /*...
I just don't know where exactly to put it in the file so it wont error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.