m developing a Next.js application using a monorepo structure with Yarn workspaces. My monorepo has two main workspaces: “starter” and “core”. The “core” workspace contains most of the functionalities such as helper functions and context, and it is published as an NPM package. The “starter” workspace is my main project which consumes the “core” package.
Everything works fine when I use the “core” workspace directly from the source. However, after publishing the “core” workspace as an NPM package and then using it in my “starter” workspace, I encounter the following error:
Error: NextRouter was not mounted.
I’m using [email protected] pages route for both my main project and the custom NPM package. Below an example of the package code that uses useRoute:
// Example from NPM package code
import { useRouter } from "next/router"
export const useDataHandling = () => {
const scrollRefPagination = useRef()
const router = useRouter()
const locale = router.locale
return {
scrollRefPagination,
locale,
}
}
// How i'm consuming it
import { useDataHandling } from "@core/utils"
const { scrollRefPagination, locale } = useDataHandling()
This works well when i improve the useDataHandling directly from core workspace, but when i publish it, it throws the Error: NextRouter was not mounted
error