question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Preview error on nuxt 3 SSR using v3 module

See original GitHub issue

Hello there, Iโ€™m having issues with the preview on nuxt 3 & @nuxtjs/prismic v3.

I configured the preview in prismic as such:

Domain: http://localhost:3000 Link resolver: /preview

When launching the preview, the server throws a 500 error, useHead is not defined.

I also deployed & configured it on Netlify, and Iโ€™m getting the same error in a live environment.

I also tried my luck making a custom preview file pages/preview.vue but Iโ€™m getting the same exact error.

Versions

Additional Details

nuxt.config.ts

import { defineNuxtConfig } from 'nuxt'
import svgLoader from 'vite-svg-loader'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  buildModules: [
    '@pinia/nuxt',
    '@vueuse/nuxt',
    '@intlify/nuxt3',
  ],
  
  modules: [
    '@nuxtjs/tailwindcss',
    '@nuxtjs/prismic',
  ],

  prismic: {
    endpoint: 'xxxx',
  },

  intlify: {
    localeDir: 'locales',
    vueI18n: {
      locale: 'en-gb',
      fallbackLocale: 'en-gb',
    }
  },

  components: {
    dirs: [
      { path: '~/components', global: false},
      { path: '~/slices', global: false },
    ],
  },

  runtimeConfig: {
    public: {
    }
  },

  vite: {
    plugins: [
      svgLoader(),
    ]
  }
})

nuxt dev console

  [Vue warn]: Unhandled error during execution of setup function 
    at <Preview onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > key="/preview" >
  [nuxt] [request error] useHead is not defined
    at setup (./.nuxt/dist/server/server.mjs:22715:1)  
    at _sfc_main.setup (./.nuxt/dist/server/server.mjs:22755:23)  

.nuxt/dist/server/server.mjs

const _sfc_main = {
  __name: 'preview',
  setup(__props, { expose }) {
  expose();

useHead({ // <---- Error thrown here
	title: 'Prismic Preview - Loading'
})

// TODO: refactor into simple hook
const { client, options: { linkResolver } } = usePrismic()
const { push } = useRouter()
__vite_ssr_import_0__.onMounted(async () => {
	const redirectURL = await client.resolvePreviewURL({
		linkResolver,
		defaultURL: '/'
	})

	push(redirectURL ?? '/')
})

Steps to reproduce

  • Install and configure @nuxtjs/prismic in nuxt.config.ts
  • Setup preview on prismic
  • Click the preview icon in UI
  • Error useHead is not defined shows up

What is Expected?

Preview working properly

What is actually happening?

Error 500 useHead is not defined

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:15

github_iconTop GitHub Comments

2reactions
renardsascommented, Jul 1, 2022

Thanks for the follow up and the commits ๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™

And also a big thank you for this article: https://lihbr.com/blog/pushing-nuxt-js-static-generation-one-step-further At the time, this approach provided excellent performance

2reactions
lihbrcommented, Jul 1, 2022

Alright, 3.0.0-alpha.10 should be the one ๐Ÿ™

Edit: Just tried with the production package, works as expected ๐Ÿ‘Œ

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxt.js - Not able to preview NuxtJs3 build - Stack Overflow
My Nuxt 3 Project is suddenly giving me some error after release of 3.0.0-rc.5, it used to work well and now i am...
Read more >
v3.0.0-rc.10 ยท Discussion #7513 ยท nuxt/framework - GitHub
This feature helps to improve the First Contentful Paint (FCP) metric. You can disable the feature from nuxt.config using experimental: { inlineSSRStyles:ย ...
Read more >
Error handling ยท Get Started with Nuxt
Learn how to catch errors in different lifecycle. Handling Errors. Nuxt 3 is a full-stack framework, which means there are several sources of...
Read more >
Preview Mode - Nuxt
The preview mode will automatically refresh the page data as it uses $nuxt.refresh under the hood and therefore calls nuxtServerInit, asyncData and fetch...
Read more >
How to Configure SSG and SSR on Nuxt.js - Mad Devs
Storing; SSG; SSR. Separately, I will show you how to set up SSG, SSR in production and create your own API using nuxt...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found