#SSR Page using @libsql/client fails on Netlify

92 messages · Page 1 of 1 (latest)

jovial totem
#

I have tried every single strategy that is recommended to solve this problem, and I am not sure if this has to do with the specific dependency (@libsql/client) or something else. But no matter what, when I deploy my project (private repo) I get the following error when accessing any endpoint:

#

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)

jovial totem
#

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

jovial totem
#

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

jovial totem
#

I think this is an Astro issue:

#

Searching for better-sqlite3 and this is the only instance

jovial totem
#

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

jovial totem
#

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

jovial totem
#

Another hour, another error. Using netlify serve locally, I'm getting:

TypeError - lambdaFunc[lambdaHandler] is not a function
green stag
#

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

jovial totem
#

From both

green stag
#

Alright, thanks

jovial totem
#

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

green stag
#

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

jovial totem
#

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

green stag
#

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

jovial totem
#

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

green stag
#

No worries, this sounds incredibly frustrating. There are a ton of moving parts here

jovial totem
#

I agree

green stag
#

I'm definitely hitting problems immediately just including @libsql/client in the bundle

jovial totem
#

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

jovial totem
#

It seems very sus that a single dep could break the bundler though

green stag
jovial totem
#

Well, in this specific way

green stag
#

Netlify blows up on a bunch of packages

jovial totem
#

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

green stag
#

Also seeing page2.page is not a function in a very minimal repro, so that's something

jovial totem
#

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

green stag
#

Nope, not using split

jovial totem
#

Should I try moving to straightup output: 'server', been using 'hybrid'

green stag
#

Nope, wouldn't make a difference

#

So... rest assured this is not a skill issue! 😅

jovial totem
#

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"

green stag
#

I can't say that I do either, Netlify config confuses the heck out of me

jovial totem
#

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?

green stag
#

Probably best to make an issue on the Astro repo

#

!issue

wide oceanBOT
jovial totem
#

ok

green stag
jovial totem
#

Man, after 25 years I sometimes wish I could just go back to FTPing to a cgi-bin folder 😂

green stag
#

I feel ya

jovial totem
#

Thank you for being so helpful. I definitely felt on an island (no pun intended) for a while there

green stag
#

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

jovial totem
#

Nothing interesting at all about @libsql/client package itself

#

Thanks again!

sinful vault
#

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.

jovial totem
#

That's not a bad idea

#

What's the earliest version with support for Server Endpoints

green stag
#

Unfortunately middleware is a newer feature, so I don’t think you could go back too far. 2.6?

sinful vault
#

I followed up with the issue on github