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:
- Placing assets in /static/
- Placing assets in /src/lib
- 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