Hi,
We have a website build using Next.js 10.x and hosting it on netlify. It’s a public repo GitHub - livechat/livechat-public-docs: Source of LiveChat Documentation for Developers website. and a netlify url is https://livechat-public-docs.netlify.app.
We are using an external library called GitHub - Redocly/redoc: 📘 OpenAPI/Swagger-generated API Reference Documentation for OpenAPI format pages.
The library works fine on the client side, however I’m getting a weird error when trying to use it with getStaticProps
:
11:00:53 AM: Error message
11:00:53 AM: A Netlify Function failed to require one of its dependencies.
11:00:53 AM: Please make sure it is present in the site's top-level "package.json".
11:00:53 AM: In file "/opt/build/repo/netlify/functions/next_test/next_test.js"
11:00:53 AM: Cannot find module './traverse' from '/opt/build/repo/netlify/functions/next_test/nextPage/pages'
Link to the logs: Netlify App
import React, { useState, useEffect } from "react";
import { RedocStandalone } from "redoc";
import specs from "../configs/redoc/specs";
import configs from "../configs/redoc/configs";
const fs = require("fs");
const path = require("path");
const Page = ({ content }) => {
const [showPlaceholder, setShowPlaceholder] = useState(true);
useEffect(() => {
setShowPlaceholder(false);
}, []);
return (
<>
<RedocStandalone
spec={specs["customer-accounts-api"]}
options={configs["customer-accounts-api"]}
/>
{showPlaceholder && (
<div
dangerouslySetInnerHTML={{
__html: content,
}}
/>
)}
</>
);
};
export async function getStaticProps() {
const basePath = path.join(process.cwd(), "tmp");
const filePath = path.join(basePath, "redoc-customer-accounts-api.html");
const content = fs.readFileSync(filePath, "utf8");
return {
props: {
content,
},
};
}
export default Page;
I checked and I’m getting content fine from the file. The whole idea behind this solution is to get content on the first request for SEO purposes.
I’m not sure where this ./traverse
issue is coming from and how to fix it.
Thanks.