Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Hardcoded .output/public causing issues on Netlify #13

Open
wants to merge 2 commits into
base: experimental
Choose a base branch
from

Conversation

Anoesj
Copy link

@Anoesj Anoesj commented Nov 21, 2022

Hey!

I've run into some issues with this module when deploying a statically generated Nuxt app (using nuxt generate) to Netlify.

This module seems to assume that the output dir is always .output/public in the Nuxt source directory, because sitemaps are always basically written to path.join(nuxtInstance.options.srcDir, '.output/public), but Nitro recognizes Netlify (probably by checking process.env.NETLIFY), sets NITRO_PRESET to netlify and that changes the output directory to dist instead of .output/public. I tried to fix this in a PR, but I'm still getting some failing tests.

Could you look into this? Consider my PR just an experiment, I'm not a very experienced open source dev 😅.

You can mimic Nitro's behavior on Netlify by running NITRO_PRESET=netlify yarn build-module. If ran, the current tests fail too.

…nerate.dir` as `generate.dir` isn't documented by Nuxt and a Nuxt module should probably not change a user's Nuxt config
@Anoesj Anoesj changed the title Hardcoded .output/public causing issues on Netlify Hardcoded .output/public causing issues on Netlify Nov 21, 2022
@d3xter-dev
Copy link
Owner

Thanks! I will have a look

@Anoesj
Copy link
Author

Anoesj commented Nov 25, 2022

Hey @d3xter-dev, I edited the original post, because I found out it has to do with the NITRO_PRESET environment variable. You can find all Nitro presets here: https://github.com/unjs/nitro/blob/main/src/presets/index.ts. This is the file where Nitro presets are resolved: https://github.com/unjs/nitro/blob/main/src/options.ts.

@ErwinAI
Copy link

ErwinAI commented Dec 18, 2022

Changes look good to me. @d3xter-dev Any chance this can be merged / released?

@Anoesj
Copy link
Author

Anoesj commented Dec 18, 2022

Tbh this probably needs some extra work if some tests are failing. It just needs an extra set of eyes for a few hours.

@offline-first
Copy link

Any updates?

@mariuscdejong
Copy link

mariuscdejong commented Jan 18, 2023

As a workaround for now, you can use this guide, replace the query with the dynamic routes.

https://content.nuxtjs.org/guide/recipes/sitemap

For example:

// server/routes/sitemap.xml.ts
import { SitemapStream, streamToPromise } from 'sitemap'

export default defineEventHandler(async (event) => {
  const config = useRuntimeConfig()
  const links = await $fetch('/api/routes')

  const sitemap = new SitemapStream({
    hostname: config.public.storyblok.siteUrl,
  })

  for (const link of links) {
    sitemap.write({
      url: link,
      changefreq: 'monthly'
    })
  }

  sitemap.end()
  return streamToPromise(sitemap)
})

Make sure to update your nuxt config to prerender the sitemap for static generation:

nitro: {
  prerender: {
    routes: ['/sitemap.xml'],
  }
}

@jankohlbach
Copy link

same issue here with vercel
at least now I know what's the issue 😅
thanks @Anoesj for the fix
@d3xter-dev is there a plan to merge this? otherwise I need to look for another solution, but this one would be the best

@andrevferreiraa
Copy link

Any plans to merge this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants