-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File operations in functions using fs fail #914
Comments
Hi gang, calling attention to this again because I think there's something flawed with netlify's approach here. I've rewritten this sitemap generator a few times now with different strategies, and I haven't found an approach that will satisfy Netlify's deploy process (though I have bumped into several which work on Vercel). |
Hi, |
Hey @ascorbic - thanks for responding. Fundamentally, the problem here seems to be that I'm using next's dynamic routing features (pages with Here's the files you asked for:
{
"/_app": "pages/_app.js",
"/_document": "pages/_document.js",
"/api/rss.xml": "pages/api/rss.xml.js",
"/api/sitemap.xml": "pages/api/sitemap.xml.js",
"/": "pages/index.js",
"/posts/[slug]": "pages/posts/[slug].js",
"/tags/[tag]": "pages/tags/[tag].js",
"/tags": "pages/tags.js",
"/work": "pages/work.js",
"/_error": "pages/_error.js",
"/en/500": "pages/en/500.html",
"/en/404": "pages/en/404.html",
"/en/about": "pages/en/about.html",
"/en/shop": "pages/en/shop.html",
"/en/newsletter": "pages/en/newsletter.html"
}
{
"version":3,
"pages404":true,
"basePath":"",
"redirects":[
{
"source":"/:path+/",
"destination":"/:path+",
"locale":false,
"internal":true,
"statusCode":308,
"regex":"^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$"
}
],
"headers":[
],
"dynamicRoutes":[
{
"page":"/posts/[slug]",
"regex":"^/posts/([^/]+?)(?:/)?$",
"routeKeys":{
"slug":"slug"
},
"namedRegex":"^/posts/(?<slug>[^/]+?)(?:/)?$"
},
{
"page":"/tags/[tag]",
"regex":"^/tags/([^/]+?)(?:/)?$",
"routeKeys":{
"tag":"tag"
},
"namedRegex":"^/tags/(?<tag>[^/]+?)(?:/)?$"
}
],
"staticRoutes":[
{
"page":"/",
"regex":"^/(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/(?:/)?$"
},
{
"page":"/404",
"regex":"^/404(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/404(?:/)?$"
},
{
"page":"/about",
"regex":"^/about(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/about(?:/)?$"
},
{
"page":"/newsletter",
"regex":"^/newsletter(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/newsletter(?:/)?$"
},
{
"page":"/shop",
"regex":"^/shop(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/shop(?:/)?$"
},
{
"page":"/tags",
"regex":"^/tags(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/tags(?:/)?$"
},
{
"page":"/work",
"regex":"^/work(?:/)?$",
"routeKeys":{
},
"namedRegex":"^/work(?:/)?$"
}
],
"dataRoutes":[
{
"page":"/",
"dataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/index.json$"
},
{
"page":"/posts/[slug]",
"routeKeys":{
"slug":"slug"
},
"dataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/posts/([^/]+?)\\.json$",
"namedDataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/posts/(?<slug>[^/]+?)\\.json$"
},
{
"page":"/tags",
"dataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/tags.json$"
},
{
"page":"/tags/[tag]",
"routeKeys":{
"tag":"tag"
},
"dataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/tags/([^/]+?)\\.json$",
"namedDataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/tags/(?<tag>[^/]+?)\\.json$"
},
{
"page":"/work",
"dataRouteRegex":"^/_next/data/2jIZI\\-rNQAgyLCot\\-QS72/work.json$"
}
],
"i18n":{
"locales":[
"en"
],
"defaultLocale":"en"
},
"rewrites":[
{
"source":"/:nextInternalLocale(en)/rss.xml",
"destination":"/:nextInternalLocale/api/rss.xml",
"regex":"^(?:/(en))/rss\\.xml(?:/)?$"
},
{
"source":"/:nextInternalLocale(en)/sitemap.xml",
"destination":"/:nextInternalLocale/api/sitemap.xml",
"regex":"^(?:/(en))/sitemap\\.xml(?:/)?$"
}
]
} |
Don't you have the same problem in |
That's true - I'm not doing a great job of explaining myself here, I apologize. For my site, I'm sourcing content from MDX files which are also in my repo, in https://github.com/mbifulco/blog/tree/main/src/data/posts All the data I need is in my repo, so I use that to cobble together the list of URLs which should appear in my sitemap, RSS, etc: |
Aah, that makes sense now! So the info you need is in |
Call me crazy, but I don't see |
It should be in |
Ah, thanks. There's some useful information in there, but I'm not sure it's a great approach for me. It looks like the I'm also a bit worried about next changing their build output format/location and breaking my sitemap and RSS feed. It feels like an antipattern to parse the output of a build command from an SSG, but again - I may be wrong here, too. Seems like I've got some thinking to do 🤔 |
I think using the manifest is actually the most robust way of doing it. Internally Next always includes the locale in URLs, but it's fine to strip the locale off as you only have one. |
It's not the most efficient solution, but your other option is to add the markdown files to the fucnitons bundle: [functions]
included_files = ["src/pages/data/*.md"] ..or somehting like that (I've not tested it). I'm going to close this for now, as we have a couple of possible workarounds. |
(note, this is carried over from a discussion in #706)
edit: related code is in this PR
Hey there - I'm trying to implement a
sitemap.xml
for my site, and running into problems when my site gets deployed to netlify. It seems to have to do with my use ofpath.join()
in my code to iterate over the files that comprise content on my site.My current strategy is to look through the
/pages
directory in my code to create an XML entry for each, using syntax like this:path.join(process.cwd(), 'src', 'pages');
This runs fine locally in dev, and when deployed on Vercel, but when I deploy to netlify, I'm seeing an error in
functions/___netlify-handler
when I try to visit the url generating my sitemap:In my case, I'm using an API Route at
/pages/api/sitemap.xml.js
to generate the sitemap, and pairing that with a redirect innext.config.js
to send the output of that function to/sitemap.xml
:I'm wondering if there's something tricky going on here because of how functions are deployed. Any guesses if this might be related to this plugin? Note that this appears to be broken even if I visit the non-redirected page /api/sitemap.xml
Originally posted by @mbifulco in #706 (comment)
The text was updated successfully, but these errors were encountered: