Joshua
Joshua

Reputation: 1403

Monorepo: Yarn workspaces not working - dependent package doesn't get installed in node_modules

I am using monorepo created using Yarn Workspaces with Typescript which has a react-native project (mobile folder) and a common folder which contains the common files to be shared across projects. Here the mobile project is dependent on common files and I have configured it referring to this doc.

When I do yarn install it show this error -> An unexpected error occurred: "https://registry.yarnpkg.com/@myapp%2fcommon: Not found".

Monorepo Structure:

packages
|---package.json
|---Common
|      |---src
|      |---package.json
|---Mobile
|      |---src
|      |---package.json

root package.json

{
"name": "monorepo",
"version": "0.0.1",
"private": true,
"workspaces": {
    "packages": ["packages/*"],
    "nohoist": [
        "**/react-native",
        "**/react-native/**",
    ]
}
}

Common's package.json

{
"name": "@myapp/common",
"version": "0.0.1",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},
"license": "UNLICENSED",
"devDependencies": {
  "@types/react": "18.0.9",
  "@types/react-native": "0.67.7",
  "@reduxjs/toolkit": "1.8.1",
  "react-redux": "8.0.1"
}
}

Mobile's package.json (react-native)

"name": "@myapp/mobile",
"version": "0.0.1",
"private": true,
...
"dependencies": {
    "@myapp/common": "0.0.1",
    "@reduxjs/toolkit": "1.8.1",
    "react": "17.0.2",
    "react-native": "0.68.2",
    ...
}
...

Any Suggestions ?

Upvotes: 0

Views: 4641

Answers (1)

Sal
Sal

Reputation: 874

Your root package.json isn't really root. Make sure your folder structure looks like this:

package.json 
packages 
|---Common
|...

Upvotes: 2

Related Questions