#@astrojs/cloudflare not all files uploaded when deploying in CF

45 messages Β· Page 1 of 1 (latest)

hazy raven
#

So im testing out the @astrojs/cloudflare package. Basic setup with

export default defineConfig({
  plugins: ['prettier-plugin-astro'],
  output: 'server',
  overrides: [{
    files: '*.astro',
    options: {
      parser: 'astro'
    }
  }],
  adapter: cloudflare()
});

Deployment goes trough without errors. But when i look at the uploaded artifacts this is the only files that gets uploaded ( see attached file) πŸ€”

And when previewing the deploy, there is just a empty response from the worker.

Aaand im not sure whats up, or what im doing wrong.

rapid pond
#

cc @spring vapor

regal roost
#

what does overrides do

#

i don't think this is the astro config

#

can you rename astro.config.mjs to .ts so it highlights if there are any errors?

#

unless the adapter was added to .prettierrc.mjs instead πŸ’€

rapid pond
#

prettier and astro configs definitely seem mixed there

spring vapor
#

The assets uploaded don't show the functions, so we can't go by this. Can you use wrangler tail or enable log streaming in Cloudflare, and do another request to a page where you see a empty page. It should show up the request and logs. If you can post that publicly, please post the logs here

hazy raven
#

This is the full astro.config.mjs

import { defineConfig } from 'astro/config';

import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  plugins: ['prettier-plugin-astro'],
  output: 'server',
  overrides: [{
    files: '*.astro',
    options: {
      parser: 'astro'
    }
  }],
  adapter: cloudflare()
});

Ill enable logs in CF and have a look

(thanks for very quick reply, didnt think anyone would answer so fast πŸ™‚ )

#

Here is the log stream from CF. I see the [ssr] Error: Network connection lost. error. There is a DB call being made in code to a postgres instance using postgresjs. Could that be the problem? πŸ€”
(some info from the log redacted)

{
  "outcome": "ok",
  "scriptName": "pages-worker--1658821-production",
  "diagnosticsChannelEvents": [],
  "exceptions": [],
  "logs": [
    {
      "message": [
        "07:57:50 PM [ssr] Error: Network connection lost.\n    at Kd (functionsWorker-0.5221137254245514.js:2635:48)\n    at new be (functionsWorker-0.5221137254245514.js:2648:428)\n    at N (functionsWorker-0.5221137254245514.js:3544:42)\n    at functionsWorker-0.5221137254245514.js:3775:167 (x2)"
      ],
      "level": "error",
      "timestamp": 1700683070942
    }
  ],
  "eventTimestamp": 1700683070796,
  "event": {
    "request": {
      "url": "https://caa5a06b.astro-web-1sc.pages.dev/",
      "method": "GET",
      "headers": {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
        "accept-encoding": "gzip",
        "accept-language": "en-US,en;q=0.5",
        "cf-connecting-ip": "*********REDACTED*********",
        "cf-ipcountry": "*********REDACTED*********",
        "cf-ray": "82a3be68784e2d98",
        "cf-visitor": "{\"scheme\":\"https\"}",
        "connection": "Keep-Alive",
        "host": "caa5a06b.astro-web-1sc.pages.dev",
        "priority": "u=1",
        "sec-fetch-dest": "document",
        "sec-fetch-mode": "navigate",
        "sec-fetch-site": "none",
        "sec-fetch-user": "?1",
        "upgrade-insecure-requests": "1",
        "user-agent": "*********REDACTED*********",
        "x-forwarded-proto": "https",
        "x-real-ip": "*********REDACTED*********"
      },
      "cf": "*********REDACTED*********"
    },
    "response": {
      "status": 500
    }
  },
  "id": 0
}
spring vapor
hazy raven
#

Oh right, doing so returns this error local. Previously I got that when trying to deploy, so i added nodejs_compat .

✘ [ERROR] 3 error(s) and 0 warning(s) when compiling Worker.


β–² [WARNING] Failed to bundle _worker.js. Error: Build failed with 3 errors:

  _worker.js:48:3212: ERROR: Could not resolve "node:events"
  _worker.js:48:3250: ERROR: Could not resolve "node:buffer"
  _worker.js:48:16760: ERROR: Could not resolve "node:stream"
#

Will add --compatibility-flags="nodejs_compat" local and see what happens

#

Added nodejs_compat locally. Spits out this error

✘ [ERROR] 09:21:09 PM [ssr] Error: Network connection lost.

      at Kd
  (file:///.../web/.wrangler/tmp/dev-4VHacN/qxzv68pb0uq.js:2725:48)
      at new be
  (file:///.../web/.wrangler/tmp/dev-4VHacN/qxzv68pb0uq.js:2738:428)
      at N
  (file:///.../web/.wrangler/tmp/dev-4VHacN/qxzv68pb0uq.js:3634:42)
      at
  file:///.../web/.wrangler/tmp/dev-4VHacN/qxzv68pb0uq.js:3865:167


[mf:inf] GET / 500 Internal Server Error (176ms)
[mf:inf] GET /favicon.ico 404 Not Found (6ms)
spring vapor
#

πŸ‘€ I never saw that kind of output... My guess you have something in the SSR part of your app, which Cloudflare / Miniflare (Wrangler), does not like.

hazy raven
#

alright. let me do the "remove all code and put it back piece by piece in until it breaks". Maybe that will be quickest way to see what is happening

spring vapor
#

My personal way of debugging those issues is to add logs after each line of code and see where it exactly fails, but that is not a good suggestion.

#

But my quess, it's something db related

regal roost
#

what is the library name

#

you mentioned postgresjs but that is not an exact match for an npm library

#

unless you mean the 7 year old one

hazy raven
#

I quickly commented out everything, works. Added in some DB shenanigans. Does not work. So its DB related yes.

#

Let me investigate a bit more

#

And, the potato code that i setup now is a initial "testing out Astro and POC". I have just dumped the sql straight in to the .astro file... Maybe this should be done in an astro endoint instead πŸ€”

spring vapor
#

Following the readme it needs node_compat which is not supported with pages.

#

Pages only supports nodejs_compat

#

You can deploy Astro to Workers though

#

Or you could use different psql lib which is fully supported on the edge

#

or You could use Hyperdrive. Those are my ideas. Sorry that it is not quite clear. Their node_compat & nodejs_compat modes are confusing, but I think they are going to rework them.

hazy raven
#

Oh i see i missed the node_compat / nodejs_compat

#

Alright but then i guess.... Let's try out deploying to a worker instead then, i do like the postgres lib πŸ˜„

#

Thank you very much for the help @spring vapor and every one else. Very much appreciated.

#

I will dig around a bit more and post my findings / solutions here when there are any! πŸ‘πŸ»

supple marten
#

i dont know if i should start another thread but im getting the opposite issue. i have a package containing assets for multiple projects, i only import what i need but astro bundles ALL assets in the package, also using the cloudflare adapter

spring vapor
hazy raven
#

Small update: So i have not had any luck what so ever with this. Tested workers, same-ish problems. Might be PEBCAK.

#

tl;dr what i have done now is to look in to Digital Ocean functions to setup a simple API that can be queried instead. DO functions do work "as expected" as in, i can write sql and it works as i would assume (since its a node environment

spring vapor
#

Very sorry to hear. I definetly used Cloudflare with sql queries before, without any issue. However to be able to debug this in more detail we would need a minimal reproducible example :/

hazy raven
#

let me put up a repro. im convinced im doing something wrong... but i do not understand what πŸ˜„

hazy raven
#

Here is a repo with minimal reproduction. The DB is a managed postgres db on Digital Ocean