nuxt-modules / nuxt-modules/strapi

useStrapi breaks `npm run generate`

Open
#417 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
717
Forks
89
Avg merge
7h 3m
Merged PRs (30d)
6

Description

Version

@nuxtjs/strapi: v1.12.0
nuxt: v3.11.2

Reproduction Link

https://github.com/kasperjha/nuxtjs-strapi-generate-issue

In app.vue you'll find the following:

<template>
  <div>
    <h1>@nuxtjs/strapi payload extraction test</h1>
    <p>Data from the "test" collection should be prerendered below</p>
    <code>{{ data }}</code>
  </div>
</template>

<script setup lang="ts">
// this breaks on `npm run generate`
const strapi = useStrapi()
const data = await strapi.findOne('test');

// this useFetch example works as expected
// const strapiUrl = useStrapiUrl()
// const data = await useFetch(strapiUrl + '/test');
</script>
Steps to reproduce
  • Create a test collection in your strapi instance
  • Clone the repo, install dependencies and point the STRAPI_URL env variable to your instance
  • Execute npm run generate in your terminal

The command fails

  • (optionally) verify no failure when using commented example code instead
What is Expected?

I expect no errors to be thrown when running npm run generate.

What is actually happening?

npm run generate fails with the error messages

...
Errors prerendering:
[nitro 1:06:18 AM]   ├─ / (65ms)
  │ └── Error: [500] 
[nitro 1:06:18 AM] 

[1:06:18 AM]  ERROR  Exiting due to prerender errors.

  at prerender (node_modules/nitropack/dist/chunks/prerender.mjs:218:11)
  at async node_modules/nuxt/dist/index.mjs:3471:7
  at async build (node_modules/nuxt/dist/index.mjs:5001:5)
  at async Object.run (node_modules/nuxi/dist/chunks/build.mjs:95:5)
  at async Object.run (node_modules/nuxi/dist/chunks/generate.mjs:56:5)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1648:16)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1639:11)
  at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1777:7) 

[1:06:18 AM]  ERROR  Exiting due to prerender errors.
...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked reproduction, inspect app.vue, and run npm run generate with useStrapi() enabled. Compare the failing prerender path with the working useFetch example; done means the reproduction generates successfully without prerender errors while fetching the test collection through useStrapi().

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
build-system, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.