I am trying to build static sites with svelte-kit using static-adapter, but when I try to build a project the build process end with error showing that md-parser is not present. I am using this parser for parsing md files with page content served from headless cms.
When I run this code in dev mode using node everything works fine, but when I try build it it runs into error.
> Using @sveltejs/adapter-static
TypeError: parseMD is not a function
My code index.json.js file:
import fs from "fs";
import parseMD from "parse-md";
export function get() {
const fileContents = fs.readFileSync("content/pages/home.md", "utf8");
const pageData = parseMD(fileContents);
let body = JSON.stringify(pageData);
return {body}
}
And there is a index.svelte file:
<script context="module">
export async function load({ fetch }) {
const pageData = await fetch(`index.json`).then((r) => r.json());
console.log(pageData);
return {
props: { pageData },
};
}
</script>
<script>
export let pageData;
</script>
<div class="container">
<h1>{pageData.metadata.text}</h1>
{pageData.content}
</div>
Can you help me please? How can I parse md files without allowed 3th party lib imports in *.json.js files?
Thank you for any advice.