prismicio-community / nuxt-starter-prismic-blog

Blog project with Nuxt & Prismic
https://nuxt-starter-prismic-blog.vercel.app
Apache License 2.0
55 stars 32 forks source link

Preview page throws errors on nuxt generate #1

Closed bchiang7 closed 5 years ago

bchiang7 commented 5 years ago

Hi there @levimykel, with a fresh clone of this repo I'm getting an error from the preview page when I run npm run generate. It seems to be originating from the api.previewSession call, which uses the node-fetch package. Any ideas how to resolve this?

ERROR   /Preview

TypeError: Only absolute URLs are supported
    at getNodeRequestOptions (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1284:9)
    at /Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1370:19
    at new Promise (<anonymous>)
    at Object.fetch (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1367:9)
    at Object.fetch (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/cross-fetch/dist/node-ponyfill.js:10:20)
    at /Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:15462
    at u (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:15788)
    at t.request (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:15965)
    at t.request (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:18843)
    at /Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:4349
    at new Promise (<anonymous>)
    at t.previewSession (/Users/brittanychiang/Documents/personal/nuxtjs-blog/node_modules/prismic-javascript/dist/prismic-javascript.min.js:1:4310)
    at asyncData (prismic.config.js:5:0)
    at process._tickCallback (internal/process/next_tick.js:68:7)
phillysnow commented 5 years ago

Hi @bchiang7 ,

The nuxt plugin does not currently support preview in when generating a static site. For the time being we suggest deploying as a server side rendered app using a service like Heroku .

Thanks, Phil.

bchiang7 commented 5 years ago

Gotcha, thanks!

TylerOrtiz commented 4 years ago

I realize this is closed and the answer makes sense, but if you wanted to have the generate command work with this example you could exclude the Preview route with configuration:

nuxt.config.js:

 generate: {
    exclude: [
      /^(?=.*\bPreview\b).*$/
    ]
  }
phillysnow commented 4 years ago

This sample has now changed, so it works with the generate command. So including the above exclude will break the now break the generate process.

Check out this article for migrating old projects to the new module. https://prismic.io/docs/vuejs/getting-started/the-new-prismic-nuxt-module