2

I am new in monorepo or yarn workspace .So learning I follow this starter boilerplate

https://github.com/belgattitude/nextjs-monorepo-example

I forked the above example .And run yarn command on root folder .Initially I got this error Couldn't find package "@your-org/core-lib@workspace:*"

I resolved above error by using version instead of * I resolve above error like this

 "@your-org/ui-lib": "3.1.2",
  "@your-org/core-lib": "3.2.2",

instead of

"@your-org/ui-lib": "workspace:*",
"@your-org/core-lib": "workspace:*",

Then when I run yarn my all packages are installed on root directory.when I move inside directory using cd apps/blog-app and run yarn dev .my application run perfectly and show the first page.

NOTE : I don't start anything like example ui-lib and core-lib.but when I change anything on core-lib .it automatically reflecting .Not sure how it is happening without watch or build command. ??

Now I create a new nextjs app in apps folder. I used this command yarn create next-app --typescript with a name of new-app. but when I run yarn dev it is successfully build and run .but I am trying to use this "@your-org/core-lib" package in my new app .I am getting module not found error.

I have already used yarn add @your-org/core-lib in new-app directory not on root directory but this still getting same error Module not found: Can't resolve '@your-org/core-lib' ?

"dependencies": {
    "next": "11.0.1",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "@your-org/core-lib": "3.2.2"
  } 

I am using like this

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import { sayHello } from '@your-org/core-lib';

export default function Home() {
  return (
    <div className={styles.container}>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
 <ul>
          <li>{`Foo says: ${sayHello('World')} from @your-org/core-lib`}</li>
        </ul>
    

     
    </div>

here is my whole code https://replit.com/@naveennsit/nextjs-monorepo-example#apps/new-app/pages/index.tsx

kindly suggest where I am doing wrong? any sugesstion

user5711656
  • 3,310
  • 4
  • 33
  • 70

0 Answers0