Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lerna error: package.json does not exist, have you run lerna init? #1835

Closed
artembatura opened this issue Dec 23, 2018 · 15 comments
Closed

Lerna error: package.json does not exist, have you run lerna init? #1835

artembatura opened this issue Dec 23, 2018 · 15 comments

Comments

@artembatura
Copy link

I run lerna bootstrap

Current Behavior

> lerna bootstrap
lerna notice cli v3.8.0
lerna ERR! ENOPKG `package.json` does not exist, have you run `lerna init`?

Expected Behavior

Should work

Specs

lerna.json

{
  "version": "0.0.5-alpha.0",
  "packages": ["packages/*"],
  "npmClient": "yarn",
  "useWorkspaces": true
}

package.json

{
  "private": true,
  "workspaces": [
    "packages/*",
    "examples/*"
  ],
  "devDependencies": {
      "lerna": "^3.8.0"
  }
}

Executable Version
lerna --version 3.8.0
npm --version 6.5.0
yarn --version 1.13.0
node --version v11.4.0
OS Version
Windows 10 x64 1703
@artembatura artembatura changed the title package.json does not exist` lerna ERR! ENOPKG package.json does not exist, have you run lerna init? Dec 23, 2018
@artembatura artembatura changed the title lerna ERR! ENOPKG package.json does not exist, have you run lerna init? Lerna error: package.json does not exist, have you run lerna init? Dec 23, 2018
@artembatura
Copy link
Author

artembatura commented Dec 23, 2018

It's work if i add field name to package.json with value root

@artembatura
Copy link
Author

It's strange behavior, because lerna in some projects works without field name in package.json :/

@evocateur
Copy link
Member

You're using Yarn workspaces, why bother with lerna bootstrap at all? It's just calling yarn install.

@evocateur evocateur added the yarn label Dec 27, 2018
@artembatura
Copy link
Author

@evocateur I just started recently using monorepo architecture with lerna + yarn workspaces . I don't know how to better. I have no found best practices guides to get started with this technologies, therefore i just learned it by examples on Github. I would be glad if you would guide me on the right path ^^

@evocateur
Copy link
Member

We should definitely improve the error message in this case, I agree.

@stale
Copy link

stale bot commented Feb 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2019
@artembatura
Copy link
Author

artembatura commented Feb 26, 2019

Up!

@stale stale bot removed the stale label Feb 26, 2019
@christophercr
Copy link

christophercr commented Oct 15, 2019

I confirm that the solution mentioned by @artemirq works: adding a "name": "root" field to the package.json solves the issue.

And indeed, this error happens sometimes 😕

@evocateur do you foresee any fix for this problem?

kenjinp added a commit to BlueBrain/nexus-js that referenced this issue Oct 23, 2019
kenjinp added a commit to BlueBrain/nexus-js that referenced this issue Oct 23, 2019
julienmachon pushed a commit to BlueBrain/nexus-js that referenced this issue Oct 23, 2019
* yarn upgrade to fix security issue

* fix lerna issue lerna/lerna#1835

* Revert "fix lerna issue lerna/lerna#1835"

This reverts commit 0318a77.

* trying to fix the package.json doesn't exist issue in CI
@aalexgabi
Copy link

Same error when version field is missing in lerna.json

@jalovatt
Copy link

I've just started seeing this issue after upgrading a Yarn 2 project that's been working fine with Lerna to v4, but we already have the config options mentioned above as causing trouble if they're absent:

// lerna.json
{
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "npmClient": "yarn",
  "useWorkspaces": true
}

@artembatura
Copy link
Author

@jalovatt Why you needed Lerna? Yarn contain most of functionality for working with workspaces.

@jalovatt
Copy link

@jalovatt Why you needed Lerna? Yarn contain most of functionality for working with workspaces.

That's what we ended up doing. Our biggest use for Lerna was the versioning tool, but yarn version check -i is close enough.

@MatriXiao88
Copy link

MatriXiao88 commented Apr 14, 2021

I confirm that the solution mentioned by @artemirq works: adding a "name": "root" field to the package.json solves the issue.

And indeed, this error happens sometimes 😕

@evocateur do you foresee any fix for this problem?

I think I find the exception reason.
Your project folder name, like Z2l0bGFiLmd6LmN2dGUuY24vc3NwYy9vcHMvc2VudHJ5LWphdmFzY3JpcHQuZ2l0LTQ3Mzk= , is incompatible with the package, named npm-package-arg, code here will throw an exception, and this.project.manifest will be undefined. Finally you will get this issue.

That will happen when you clone a repo and you specific invalid target folder name.

You can set valid name in package.json file to avoid this issue. See code here

@wpyoga
Copy link

wpyoga commented Oct 31, 2021

@Rhuaer Yes, you are right. If the directory (folder) name is not a valid name as defined here, and "name": "root" property is missing, then this error will come up.

How to reproduce:

$ mkdir test-lerna@1
$ cd test-lerna@1
$ yarn add lerna
$ yarn lerna init

At this point, open package.json and remove the name property. Then:

$ yarn lerna bootstrap
yarn run v1.22.17
$ /home/william/Documents/wpyoga/test-lerna@1/node_modules/.bin/lerna bootstrap
lerna notice cli v4.0.0
lerna ERR! ENOPKG `package.json` does not exist, have you run `lerna init`?
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Note that if the directory name is valid, then yarn lerna init won't create the name property at all, and yarn lerna bootstrap will still succeed.

So it seems to me that yarn lerna init knows that the directory name is invalid and proactively adds the name property with the value root. According to validate-npm-package-name, the directory name is an invalid npm package name:

> require('validate-npm-package-name')('test-lerna@1')
{
  validForNewPackages: false,
  validForOldPackages: false,
  errors: [ 'name can only contain URL-friendly characters' ]
}
> require('validate-npm-package-name')('test-lerna')
{ validForNewPackages: true, validForOldPackages: true }

I think it would be super helpful if lerna bootstrap can detect this fact and inform the user, so corrective actions can be taken.

I ran into this problem when I was making a patch for docusaurus, I made a branch for the commit and used a worktree directory named docusaurus@not-require-use-ssh. Eventually everything worked after I added the "name": "root" property to package.json .

@JamesHenry
Copy link
Member

Hi Folks 👋

Please take a look at our published roadmap for Lerna v7 here: #3410

One of the key items covered at length on there (please do read it for full context) is that now that we find ourselves in late 2022, it no longer makes sense for lerna to supplement package management concerns (such as installation, boostrapping, linking etc) which are covered reliably for monorepo workspaces by the three main package managers: npm, yarn and pnpm. lerna bootstrap et al were developed in a completely different era of the JavaScript ecosystem.

If you have any specific concerns please do join in on that discussion, and provide as much context as possible.

Many thanks 🙏

@JamesHenry JamesHenry closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2022
@lerna lerna locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants