javascript - How do I add a package to my Lerna repository? - Stack Overflow

I am newbee to Lerna,learning from create lerna monorepo.My repo structuredrwxrwxr-x8 jholmes jholm

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 /@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
    │   ├── ponents
    │   │   └── 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?

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/@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
    │   ├── ponents
    │   │   └── 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?

Share Improve this question edited Jan 22, 2021 at 10:18 Richard Rublev asked Jan 22, 2021 at 9:43 Richard RublevRichard Rublev 8,17218 gold badges92 silver badges147 bronze badges 5
  • 1 Can you provide your lerna.json, please? – oozywaters Commented Jan 22, 2021 at 10:10
  • Does @myrapp/library match the package name in library/package.json? – oozywaters Commented Jan 22, 2021 at 10:14
  • @oozywaters I added packages tree. – Richard Rublev Commented Jan 22, 2021 at 10:18
  • Have you checked packages/library/package.json? It must contain correct package name "name": "@myrapp/library" and correct version. – oozywaters Commented Jan 22, 2021 at 10:24
  • "name": "library", "version": "0.0.0" – Richard Rublev Commented Jan 22, 2021 at 10:30
Add a ment  | 

2 Answers 2

Reset to default 3

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",
  ...
}

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"
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744699933a4588716.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信