【问题标题】:Nuxtjs conf error setting up github pagesNuxtjs conf 错误设置 github 页面
【发布时间】:2018-12-28 12:37:50
【问题描述】:

我想在 nuxt 中启用 github 页面进行部署。在docs 之后,虽然我无法在 conf 文件中得到正确的结果。

这是他们要在文件中添加的内容。我在文件中的多个位置添加了它,但每次都出错。

/* 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
}

我的导出代码。

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)

错误

 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! github@1.0.0 generate: `nuxt generate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the github@1.0.0 generate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    您在第 3 行有一个格式错误的 JS 对象:

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

    所以你可以用外部声明替换,然后在export default上添加带有扩展运算符...的变量:

    const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ?
      {router: {base: '/mortalcatalyst.github.io/'}} :
      {}
    
    export default {
      ...routerBase,
      /*
       ** Headers of the page
       */
      head: {
    
      }
    }
    

    【讨论】:

    • 我仍然收到同样的错误。它也在编辑器中显示相同的语法错误。我更改为看起来像您的代码,但对我来说似乎相同。
    • module.exports = { mode: 'spa', const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {router: {base: '/mortalcatalyst.github.io/'}} : {} export default { router: {base: '/mortalcatalyst.github.io/'}, /*...
    • 我只是不知道将它放在文件中的确切位置,所以它不会出错。
    猜你喜欢
    • 2021-08-24
    • 2019-02-04
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    相关资源
    最近更新 更多