Skip to content
Advertisement

Fetch local JSON and display a list in Next.js. Property ‘data’ does not exist on type String

I am trying to get the names displayed of a ‘Crate’ (a crate full of records/albums), derived from a local JSON file. But it’s not showing up. Should I be using params? Should I have not stringified the JSON? VSC tells me Property ‘data’ does not exist on type String. Before this I received an error that crates.map is not a function, indicating that the JSON was an object not an array.

public/data.json

JavaScript

index.tsx

JavaScript

Advertisement

Answer

No need to stringify since response is json

JavaScript
Advertisement