Search code examples
github-pagesnuxt3.js

Nuxt 3 on Github pages with nuxt-svgo: "Failed to execute 'createElement' on 'Document': The tag name provided"


I'm building my Nuxt 3 application to Github Pages by running "npm generate" to build the static files. While the dev and production builds work fine locally, it doesn't work when it gets pushed to Github Pages.

When I open the Github Pages site, I get the error:

Failed to execute 'createElement' on 'Document': The tag name provided ('https://customdomain.com/_nuxt/logo.6cc77fc4.svg') is not a valid name.

What perplexes me is when I navigate to https://customdomain.com/_nuxt/logo.6cc77fc4.svg, the SVG image exists! Why isn't it able to load it then?


Solution

  • Turns out this was all a side effect of having the "actions/configure-pages@v3" action run as a step in my Github Actions deployment workflow. I copied the file from GitHub's own template, but using it caused parts of my site to not build -- including the svgs, TailwindCSS, etc.

    Here's my final workflow file:

    # Sample workflow for building and deploying a Nuxt site to GitHub Pages
    #
    # To get started with Nuxt see: https://nuxtjs.org/docs/get-started/installation
    #
    name: Deploy Nuxt site to Pages
    
    on:
      # Runs on pushes targeting the default branch
      push:
        branches: ['main']
    
      # Allows you to run this workflow manually from the Actions tab
      workflow_dispatch:
    
    # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
    permissions:
      contents: read
      pages: write
      id-token: write
    
    # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
    # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
    concurrency:
      group: 'pages'
      cancel-in-progress: false
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v3
          - name: Setup Node
            uses: actions/setup-node@v3
            with:
              node-version: '16'
              cache: npm
              cache-dependency-path: './package-lock.json'
          - name: Install dependencies
            run: npm install
          - name: Static HTML export with Nuxt
            run: npm run generate
          - name: Deploy
            uses: JamesIves/github-pages-deploy-action@v4
            with:
              branch: gh-pages # The branch the action should deploy to.
              folder: .output/public # The folder the action should deploy.
              token: ${{ secrets.ACCESS_TOKEN }}