nuxt-directus: Error: Cannot read properties of undefined (reading '_data')
Version
nuxt-directus: 5.6.0 nuxt: 3.8.2
Reproduction Link
https://github.com/hi-reeve/nuxt-directus-test
Steps to reproduce
- use nuxt-directus with asyncData
- an error occured
- set asyncdata option to
server:false
- data fetched
What is Expected?
- fetching data on serverside with no error
nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
runtimeConfig: {
dbConnectionString: process.env.DIRECTUS_DIRECT_URL,
directus: {
url: process.env.DIRECTUS_APP_URL,
},
},
modules: ["@nuxt/image", "@unocss/nuxt", "nuxt-directus"],
imports: {
dirs: ["libs/**", "composables/**"],
},
directus: {
devtools: true,
url: process.env.DIRECTUS_APP_URL,
token: process.env.DIRECTUS_API_TOKEN,
},
experimental: {
componentIslands: true,
typedPages: true,
},
});
the code
<script setup lang="ts">
import { type Blog } from "@/types/blog";
const { getItems } = useDirectusItems();
const {
data: blogList,
pending: loading,
error,
} = await useAsyncData("bloglist", () =>
getItems<Blog>({
collection: "blog",
})
);
const { data: blogListClient, pending: loadingClient } = await useAsyncData(
"bloglist-client",
() =>
getItems<Blog>({
collection: "blog",
}),
{
server: false,
}
);
</script>
<template>
<div>
<div>
<p>Server Side</p>
<div>
{{ error }}
</div>
<p v-if="loading">Loading...</p>
<pre v-else>{{ blogList }}</pre>
</div>
<div>
<p>Client side</p>
<p v-if="loadingClient">Loading...</p>
<pre v-else>{{ blogListClient }}</pre>
</div>
</div>
</template>
the result
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 23 (3 by maintainers)
thankyou!
So, I can confirm that on
18.16.0
there is indeed a fetch issue, so updating it is the way to go.But now that I think about it I remember reading in the nuxt
3.8.0
release a fetch rewrite using native node fetch for nitro2.7.0
, more in particular in nitro/#724.Anyway, I would consider this issue closed since, to me, it does not seem to be directly related to nuxt-directus itself, but just a combination of node+nuxt versions
I’ll try to test it, once I get back home
yes i tried everything including axios. and the result the same. the only solution is to upgrade node version
I have a very similar problem. “createItems” throws an error “Cannot read properties of undefined (reading ‘data’) at createItems”, although creation is successful and everything works as expected.
UPD: That was my fault. After creating an item, the directus should return the ID, but it couldn’t because my access rights prohibited reading these items, only creation was allowed. And therefore, “createItems” threw an error even if successful.