#SSR Page using @libsql/client fails on Netlify
92 messages · Page 1 of 1 (latest)
I've tried using output: 'server' and output: 'hybrid', I've tried external_node_modules, I've tried splitting the page files
Everything works perfectly on local dev (pnpm run start)
Ok, I've narrowed this down to just when @libsql/client gets invoked in a SSR Astro page (NOT from an endpoint)
SSR Page using @libsql/client fails on Netlify
After specifying esbuild as the bundler explicitly, I now see errors about a constructor not being defined even though looking at the code it definitely is defined
I think this is an Astro issue:
Searching for better-sqlite3 and this is the only instance
After using vite.optimizeDeps.include on this dependency, I'm now getting
I don't even know anymore
So in my pageMap I have
var _page7 = () => Promise.resolve().then(() => (init_do_signup_ts_026f3bc9(), do_signup_ts_026f3bc9_exports));
But then when you follow that chain....
var init_do_signup_ts_026f3bc9 = __esm({
".netlify/functions-internal/chunks/do_signup@_@ts.026f3bc9.mjs"() {
init_renderers();
init_middleware_a654fe57();
init_astro_6e8910be();
init_do_login_ts_8427aaf5();
init_lib_esm2();
page8 = () => Promise.resolve().then(() => (init_do_signup_ts_4b3a0f5c(), do_signup_ts_4b3a0f5c_exports));
}
});
This is in the Astro created functions
Further down this rabbit hole: This is the manifest.routes:
[
{
file: 'index.html',
links: [],
scripts: [],
styles: [],
routeData: [Object]
},
// ... A bunch of others
{
file: '',
links: [],
scripts: [],
styles: [Array],
routeData: [Object]
},
{
file: '',
links: [],
scripts: [],
styles: [Array],
routeData: [Object]
}
]
There is a bunch of those routes where file is an empty string
Another hour, another error. Using netlify serve locally, I'm getting:
TypeError - lambdaFunc[lambdaHandler] is not a function
OK I am sitting down to look at this now, sorry this has been so frustrating!
Is @libsql/client being called from a src/pages/some-file.astro or from a middleware handler?
Having access to your repo would help a lot since it seems like there are many layers to this, but I'll try to setup a minimal reproduction
From both
Alright, thanks
The thing that I see when I debug netlify serve is that when it tries to require the entry.js file it gets back an empty module
And it seems that's because there are two separate entry_exports variables created, and the one that is exported is never assigned any values
I could share this entry.js file with you, or screen share / code share whatever if that's helpful
Yeah trying to think of the best way to debug. I absolutely believe this is a bundling issue, I'm just trying to figure out if the output is from Astro's build process or the secondary Netlify build process
Who creates ./.netlify/functions-serve/entry/src/.netlify/functions-serve/.unzipped/entry/entry.js ?
I believe it's Astro since it's created with pnpm run build
But maybe the netlify adapter affects the build output?
I guess that's exactly what it would do
Yeah everything is built by Astro (in one way or another), I'm not passing the blame to Netlify here
Just that Astro has a build process, then the Netlify adapter has to bundle things again to run on Netlify
But I can PLAINLY see that what is exported from that file will be an empty module
There is no mechanism by which there will be anything in it. There's exactly two references to entry_exports, where it is declared, and where it is passed to _toCommonJS
It doesn't looks like the .unzipped entry.js even gets executed from the require (but node debugger sometimes freaks out and skips some breakpoints)
By the way, I really appreciate your help
This has been probably the most frustrating issue I've had outside of work in years
No worries, this sounds incredibly frustrating. There are a ton of moving parts here
I agree
I'm definitely hitting problems immediately just including @libsql/client in the bundle
I really thought this was gonna be a fast way to get this thing out the door. I feel like just spooling up a DO droplet and putting a node container up there would have been much faster
Interesting
It seems very sus that a single dep could break the bundler though
You'd be surprised, it happens all the time
Well, in this specific way
Netlify blows up on a bunch of packages
We have issues at my company with our internal build tools with certain internal packages
It seems there are similar problems in a lot of the serverless platform adapters, combing through the issues
Also seeing page2.page is not a function in a very minimal repro, so that's something
Yes, I've seen page19.page is not a function
It started, as you can see, with better-sqlite3 not being included
So I told Vite to ensure it's included in the bundle
That went away (after trying about 14 different ways to "fix" it)
Then I had that page issue, so I refactored a page away from being prerendered with data loading in the front matter, to having it loaded by a component that is client:only
And moving the fetching into a new endpoint
And that's how I got here
Are you using split?
Removing it for me didn't change anything
Nope, not using split
Should I try moving to straightup output: 'server', been using 'hybrid'
Nope, wouldn't make a difference
I'm totally lost already in the Netlify logs and this is the simplest possible version https://github.com/natemoo-re/bug--astro-netlify-libsql
So... rest assured this is not a skill issue! 😅
That's awesome to know 😂
I added @libsql/client to external_node_modules and it didn't change a thing either
(Which I still don't exactly understand why that's important"
I can't say that I do either, Netlify config confuses the heck out of me
It sucks. I've used Netlify for almost 5 years now and they've always been great to work with
But this is the first time I've used their functions product
So should we wrap this up into a formal issue? And on what repo?
And what would your advice be if I want to ship this product out quickly (within next week)? Use node adapter? Rewrite in something else completely? Wait?
Open a New Issue
https://github.com/withastro/astro/issues/new/choose
ok
Yeah great question! If the Node adapter is an option and you could spin it up quickly, that's definitely a good route. Turso is definitely something we want to support so I can absolutely dig into this more next week, but no promises it will get resolved within your timeframe!
Man, after 25 years I sometimes wish I could just go back to FTPing to a cgi-bin folder 😂
I feel ya
Thank you for being so helpful. I definitely felt on an island (no pun intended) for a while there
So sorry about that! I'm guessing our support squad folks didn't even know where to start with this one since there are so many layers to it
I need to bounce, but definitely ping me when you make an issue and I'll make sure to prioritize it!
Hoping we can get this resolved quickly, and thankfully we have some great Netlify connections to lean on if it comes to that
I will look into it Monday/Tuesday. The fact that changing the adapter yields weird results is definitely useful. It's not an adapter thing but a bundling thing with that library.
One thing that we could try is to see the outcome with an older version of Astro. Maybe 2.3 or something.
That's not a bad idea
What's the earliest version with support for Server Endpoints
Unfortunately middleware is a newer feature, so I don’t think you could go back too far. 2.6?
I followed up with the issue on github