1

I have a Directus instance (backend) hosted on a heroku dyno that is working fine.

I have a custom frontend developed with Qwik city. Everything is working fine locally (dev and build), but when I try to deploy it either on Cloudflare pages or Vercel edge it is failing.

I get a 500 error on every routes and the error logs are really unhelpful.

I only get: Error: e is not a function on Vercel and the little variant Error: t is not a function on Cloudflare pages.

The error comes from the Directus client, here is the file (https://github.com/directus/examples/blob/main/astro/src/utils/get-directus-client.js):

import { Directus } from '@directus/sdk'

import { backendConfig } from '@config/backend.config'
import type { BackendDirectusTypes } from '@shared/types/backend/directus.types'

export const getDirectusClient = async () => {
  const {
    directusPublicUrl,
    directusEmail,
    directusPassword,
    directusStaticToken,
  } = backendConfig

  const directus = new Directus<BackendDirectusTypes>(directusPublicUrl)

  if (await directus.auth.token) return directus

  if (directusEmail && directusPassword) {
    await directus.auth.login({
      email: directusEmail,
      password: directusPassword,
    })
  } else if (directusStaticToken) {
    await directus.auth.static(directusStaticToken)
  }

  return directus
}

When playing cat and mouse game with some console.log(/* ... */) it appeared that the error originated from both: await directus.auth.login({ email: directusEmail, password: directusPassword }) and await directus.auth.static(directusStaticToken)

I double checked, the environment variables exist (and are the right credentials).

It's been 48 hours I've been trying to deploy that without success. I run out of idea.

Has someone ever deployed some frontend fetching Directus data SSR on either of these providers ?

Aurélien B.
  • 498
  • 2
  • 9

1 Answers1

0

Not really sure why but it seems that the issue comes from the official @directus/sdk package.

I managed to deploy my app by not using the official sdk anymore.

I am using an unofficial sdk written by @fabian-hiller.


Theory:

It is plausible that the issue comes from the fact that the current official sdk is built using Axios.

You can have a look at the posts mentioning related-issues:

https://community.cloudflare.com/t/can-i-use-axios-in-a-worker/168139

https://developers.cloudflare.com/workers/runtime-apis/fetch

Good to know:

The directus team is actively working a new improved version of their sdk that will not use Axios anymore. Until then, I will use some unofficial packages.

Aurélien B.
  • 498
  • 2
  • 9