Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanity query in Nuxt.config.js not working after upgrade to 0.8.0 #120

Closed
4 of 5 tasks
ovsw opened this issue Apr 14, 2021 · 3 comments
Closed
4 of 5 tasks

Sanity query in Nuxt.config.js not working after upgrade to 0.8.0 #120

ovsw opened this issue Apr 14, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@ovsw
Copy link

ovsw commented Apr 14, 2021

I'm using a query in nuxt.config.js to generate dynamic routes from Sanity content.
The code below works fine in v. 0.7.1. Stops working in 0.8.0 and above because the query is returning undefined, and nuxt generate fails as a consequence.

Version

module: 0.9.0, 0.8.0 (WORKS IN 0.7.1)
nuxt: 2.15.4

Nuxt configuration

mode:

  • universal
  • spa

Nuxt configuration

import { createClient } from "@nuxtjs/sanity";
import fetch from "node-fetch";
if (!globalThis.fetch) {
  globalThis.fetch = fetch;
}

if (!globalThis.fetch) {
  globalThis.fetch = fetch;
}
const configSanity = {
  projectId: "xxxxxxx",
  useCdn: false,
  minimal: true,
  dataset: "production"
};
// create sanity client 
const client = createClient(configSanity);

export default {
  target: "static",
  buildModules: [
    "@nuxtjs/sanity/module"
  ],

}
// GENERATE DYNAMIC PAGES FROM SANITY
  generate: {
    fallback: true,
    crawler: false,
    async routes() {
      // the pages  const below returns undefined in 0.8.0 and above. works fine in 0.7.1
      const pages = await client.fetch(`*[_type == "page"]`);
     
      return [
        ...pages.map(page => {
          return {
            route: `/${page.content.slug.current}/`,
            payload: page
          };
        })
      ];
    }
  },

What is expected?

await client.fetch(*[_type == "page"]); returns sanity content.

What is actually happening?

await client.fetch(*[_type == "page"]); returns undefined

Steps to reproduce

basic nuxt install with config adjusted as above

Additional information

This same code works fine in module version 0.7.1. Fails in 0.8.0 and above because the sanity query is not returning any data.

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet
@ovsw ovsw added the bug Something isn't working label Apr 14, 2021
Copy link
Collaborator

@ovsw This should be fixed in 0.9.1 - let me know if not 🙏

@ovsw
Copy link
Author

ovsw commented Apr 14, 2021

works fine now, thanks for the quick fix!

Copy link
Collaborator

Great! 😊

@danielroe danielroe reopened this Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants