Juan Diego
Juan Diego

Reputation: 1466

Nextjs app cannot build using shared library as part of a monorepo

I have a monorepo with pnpm and I have backend, and 3 nextjs apps that connect to that backend in the monorepo

/packages
         /admin -> nextjs
         /operator -> nextjs
         /backend -> nestjs
         /shared -> shared library

I am having a problem in the operator web page, I am trying to export some functions that might be used in the other projects. But functions that are part of the frontend in reactjs I get the following: enter image description here

It is linking to the project as "../shared/..." so it is going down one folder to link it so that is why I think that is why webpack has a trouble bundling the shared library.

enter image description here

This is what it shows on the pnpm-lock.yaml

Upvotes: 1

Views: 546

Answers (1)

Juan Diego
Juan Diego

Reputation: 1466

Ok, so I figured it out, I was really dumb I was adding my libraries like this

import { apiRequest } from "shared/utils/apiRequest";

And my index.ts in my library

export default {
  ...
  apiRequest,
  ...
};

I fixed the exports on src/index.ts

import { apiRequest } from "shared";

Exports in my index.ts removed default

export {
  ...
  apiRequest,
  ...
};

Upvotes: 0

Related Questions