Hi, I’m trying to use the content-api with svelte kit. I’ve put the
<script context="module">
import GhostContentAPI from '@tryghost/content-api';
export async function load() {
const api = new GhostContentAPI({
url: 'https://demo.ghost.io',
key: '22444f78447824223cefc48062',
version: 'v3.0'
});
try {
// fetch 5 posts, including related tags and authors
const posts = await api.posts.browse({ limit: 5, include: 'tags,authors' });
return { props: { status: 200, posts } };
} catch (error) {
console.log(error);
return { props: { status: 200, posts: [] } };
}
}
</script>
inside the script context module but from the client, I’m seeing this error:
Error: Module "url" has been externalized for browser compatibility and cannot be accessed in client code.
at Object.get (browser-external:url:3:11)
at dispatchXhrRequest (xhr.js:41:22)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js:16:10)
at dispatchRequest2 (dispatchRequest.js:58:10)
at Axios.request (Axios.js:109:15)
at Axios.<computed> [as get] (Axios.js:131:17)
at Function.wrap [as get] (bind.js:9:15)
at defaultMakeRequest2 (content-api.js:35:18)
at makeApiRequest (content-api.js:163:16)
I see the data correctly from the terminal.
I’m running “@tryghost/content-api”: “^1.9.3”
PS: I’ve another project with svelte kit where the API it’s working well. I don’t understand what it could be.
Thanks