Getting assets in sveltekit -- should I use the new read tool from $app/server?

Site: https://master--seanbase.netlify.app/

Hello Netlify team. I am testing out netlify services by building a small site.
Things are going smoothly, however I have a problem with importing and using assets in a sveltekit +server.js endpoint.
In this case, I am trying to import and use a font, and a png file to embed in a pdf file I generate.

There is some conflicting information online, but what I have tried is:

  1. Placing assets in /static/
  2. Placing assets in /src/lib
  3. Placing assets in the endpoint folder
    And against those three, I have tried importing the files:
import NotoFont from './NotoSansJP-Regular.ttf';
import companyLogo from './logo-cropped.png'
import { read } from '$app/server';
    const font_data = await read(NotoFont).arrayBuffer();
    const customFont = await pdfDoc.embedFont(font_data)

The pdf generation worked on my local when simply placing assets in static, but from my research that changes when deploying to netlify. Makes sense.

When doing the above, currently I get the following error in my logs:

Aug 23, 09:34:38 AM: c194eb03 ERROR  TypeError: Failed to parse URL from /_app/immutable/assets/NotoSansJP-Regular.BuIItb8O.ttfAug 23, 09:34:38 AM: c194eb03 ERROR      at node:internal/deps/undici/undici:12618:11 {Aug 23, 09:34:38 AM: c194eb03 ERROR    [cause]: TypeError [ERR_INVALID_URL]: Invalid URLAug 23, 09:34:38 AM: c194eb03 ERROR        at new NodeError (node:internal/errors:405:5)Aug 23, 09:34:38 AM: c194eb03 ERROR        at new URL (node:internal/url:676:13)Aug 23, 09:34:38 AM: c194eb03 ERROR        at new Request (node:internal/deps/undici/undici:6108:25)Aug 23, 09:34:38 AM: c194eb03 ERROR        at fetch (node:internal/deps/undici/undici:10396:25)Aug 23, 09:34:38 AM: c194eb03 ERROR        at Object.fetch (node:internal/deps/undici/undici:12617:10)Aug 23, 09:34:38 AM: c194eb03 ERROR        at fetch (node:internal/process/pre_execution:281:25)Aug 23, 09:34:38 AM: c194eb03 ERROR        at GET (file:///var/task/.netlify/server/entries/endpoints/generate-receipt/_server.js:16:30)Aug 23, 09:34:38 AM: c194eb03 ERROR        at async render_endpoint (file:///var/task/.netlify/server/index.js:180:20)Aug 23, 09:34:38 AM: c194eb03 ERROR        at async resolve2 (file:///var/task/.netlify/server/index.js:2668:22)Aug 23, 09:34:38 AM: c194eb03 ERROR        at async respond (file:///var/task/.netlify/server/index.js:2563:22) {Aug 23, 09:34:38 AM: c194eb03 ERROR      input: '/_app/immutable/assets/NotoSansJP-Regular.BuIItb8O.ttf',Aug 23, 09:34:38 AM: c194eb03 ERROR      code: 'ERR_INVALID_URL'Aug 23, 09:34:38 AM: c194eb03 ERROR    }Aug 23, 09:34:38 AM: c194eb03 ERROR  }

I am not sure why there is extra text in the filename, you can see that what I have as NotoSansJP-Regular.ttf has extra text in the filename in the logs. A hash perhaps?

One place I saw said to edit netlify.toml:

[functions]
  included_files = ["static/**"]

But this did not work either.
Anyone have any experience in this regard?
Thanks

Just to confirm, does this work if you try to prerender your site using SvelteKit’s static adapter?

Was this fixed? I am doing the same thing:

import satori from 'satori';
import { Resvg } from '@resvg/resvg-js';
import LibreSans from '$lib/fonts/LibreCaslonCondensed-Bold.ttf';
import { html as toReactNode } from 'satori-html';
import Card from '$lib/components/Primary/ShareCard.svelte';
import { read } from '$app/server';

const fontData = read(LibreSans).arrayBuffer();

const height = 630;
const width = 1200;

It works locally. But when deployed (and it does deploy, I can see logs in my Functions logs):

Oct 14, 04:55:29 PM: e1dac7cb ERROR  [Error: ENOENT: no such file or directory, open '.netlify/server/_app/immutable/assets/LibreCaslonCondensed-Bold.I4TKy7ID.ttf'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '.netlify/server/_app/immutable/assets/LibreCaslonCondensed-Bold.I4TKy7ID.ttf'
}
Oct 14, 04:55:29 PM: e1dac7cb Duration: 347.77 ms	Memory Usage: 127 MB
Oct 14, 04:55:47 PM: 9d181a60 ERROR  [Error: ENOENT: no such file or directory, open '.netlify/server/_app/immutable/assets/LibreCaslonCondensed-Bold.I4TKy7ID.ttf'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '.netlify/server/_app/immutable/assets/LibreCaslonCondensed-Bold.I4TKy7ID.ttf'
}

Any help with this? Still stuck so would be appreciated

You ignored my question and asked your own :slight_smile: