next-drupal
next-drupal copied to clipboard
Silent error when using the getMenu method and building a static output with Next.js
Package containing the bug
next (Drupal module)
Describe the bug
I don't understand if this an issue with Next-Drupal or with Next 14, but since this is a library that aims to work with Next.js as-is I'll first open the issue here.
I'm trying to build a static export with Next 14 (the output property of next.config.js is set to export
), but when I include the getMenu
method in my code, the Next build silently fails to produce the html templates of the pages (including index.html).
From Next 13 similar issues have been linked with the built-in image optimization of Next.js, but in this project I set the unoptmized
flag to true for the images property in next.config.js and the issue still happens if and only if the getMenu method is invoked.
If I replace the getMenu method with something like this the build finishes with the expected result (note that I don't need token authorization so I left it out):
async function getMenu(name: string) {
const url = drupal.buildUrl(`/jsonapi/menu_items/${name}`)
const response = await fetch(url.toString())
const serialized = await response.json()
const items = drupal.deserialize(serialized) as DrupalMenuLinkContent[]
const { items: tree } = drupal.buildMenuTree(items)
return { items, tree: tree as DrupalMenuLinkContent[] }
}
Expected behavior
I build the Next project with the static output options set to true and the created out folder contains the html files for index.html and all the pages.
Steps to reproduce:
- use the getMenu method in a reachable part of the code
- set the
output
property toexport
in thenext.config.js
file - launch the build command
- check the contents of the
out
folder for the static html files - the html files aren't there (including no
index.html
)