Richard Rublev
Richard Rublev

Reputation: 8172

How do I add a package to my Lerna repository?

I am newbee to Lerna,learning from create lerna monorepo.

My repo structure

drwxrwxr-x  8 jholmes jholmes 4096 јан 21 19:40 .git
drwxrwxr-x  3 jholmes jholmes 4096 јан 22 10:14 .history
-rw-rw-r--  1 jholmes jholmes 1133 јан 21 18:38 lerna-debug.log
-rw-rw-r--  1 jholmes jholmes   63 јан 21 18:14 lerna.json
-rw-rw-r--  1 jholmes jholmes   91 јан 21 18:14 package.json
drwxrwxr-x  4 jholmes jholmes 4096 јан 21 19:08 packages

I added myapp(Create-react-app),so packages have two folders library and myapp. When I go to myapp/package.json file and manually add below dependency to use the library package

"@myrapp/library": "1.0.0",

With

lerna bootstrap

I got error

lerna notice cli v3.22.1
lerna info Bootstrapping 2 packages
lerna info Installing external dependencies
lerna ERR! npm install exited 1 in 'myapp'
lerna ERR! npm install stderr:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@myrapp%2flibrary - Not found
npm ERR! 404 
npm ERR! 404  '@myrapp/[email protected]' is not in the npm registry.

Repo structure

.
├── lerna-debug.log
├── lerna.json
├── package.json
└── packages
    ├── library
    │   ├── lib
    │   ├── node_modules
    │   ├── package.json
    │   ├── package-lock.json
    │   ├── README.md
    │   └── __tests__
    └── myapp
        ├── node_modules
        ├── package.json
        ├── public
        ├── README.md
        ├── src
        └── yarn.lock

Packages tree

├── library
│   ├── lib
│   │   └── library.js
│   ├── node_modules
│   ├── package.json
│   ├── package-lock.json
│   ├── README.md
│   └── __tests__
│       └── library.test.js
└── myapp
    ├── package.json
    ├── public
    │   ├── favicon.ico
    │   ├── index.html
    │   ├── logo192.png
    │   ├── logo512.png
    │   ├── manifest.json
    │   └── robots.txt
    ├── README.md
    ├── src
    │   ├── App.css
    │   ├── App.js
    │   ├── App.test.js
    │   ├── components
    │   │   └── button
    │   │       ├── index.js
    │   │       └── index.stories.js
    │   ├── index.css
    │   ├── index.js
    │   ├── logo.svg
    │   ├── reportWebVitals.js
    │   └── setupTests.js
    └── yarn.lock



Lerna.json

    {
      "packages": [
        "packages/*"
      ],
      "version": "0.0.0"
    }

How to inform myapp about library?

Upvotes: 2

Views: 11947

Answers (2)

Tom Benyon
Tom Benyon

Reputation: 1051

I was using npm workspaces and forgot I had to update the root package.json workspace list as well as the lerna.json file...

-> package.json

{
  "name": "root",
  "private": true,
  "workspaces": [
    "packages/*",
    "mockApiGateway"  <- New addition
  ],
  "devDependencies": {
    "lerna": "^6.0.1",
    "nx": "15.0.4"
  }
}

-> lerna.json

{
  "$schema": "node_modules/lerna/schemas/lerna-schema.json",
  "useWorkspaces": true,
  "private": true,
  "packages": [
    "packages/**",
    "myNewPackage/"  <- New addition
  ],
  "version": "0.0.0"
}

Upvotes: 0

oozywaters
oozywaters

Reputation: 1241

You have to bootstrap your packages:

lerna bootstrap

UPD. Make sure to set correct library name and version in packages/library/package.json:

{
  "name": "@myrapp/library",
  "version": "1.0.0",
  ...
}

Upvotes: 3

Related Questions