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

npm uninstall throws 404 for unpublished siblings #1229

Open
jennasalau opened this issue Jan 22, 2018 · 15 comments
Open

npm uninstall throws 404 for unpublished siblings #1229

jennasalau opened this issue Jan 22, 2018 · 15 comments
Labels
scope: package management Issues with the bootstrap/add/link commands that relate to package management

Comments

@jennasalau
Copy link

Take the following project dependency structure

.
├── packages
    ├── module-a
        ├── dependency-a           (3rd party and published on npm)
        └── module-b               (sym link dependency from a `lerna bootstrap`)
    └── module-b                   (private/not published on npm)

cd'ing into module-a and attempting to uninstall dependency-a:

npm uninstall dependency-a

Gives the following error:

npm ERR! code E404
npm ERR! 404 Not Found: module-b@v1.0.0

For some reason (guessing clean up), NPM re-evaluates the dependent packages on a uninstall which blow's away any sym links resulting in this 404?

Potentially related to: npm/npm#17025

Expected Behavior

I would expect dependency-a to uninstall and module-a packages.json/lock files to update.

Current Behavior

npm uninstall behaviour is exited and the module is not removed.

Possible Solution

Open an issue with NPM?
Find or document a work around.

Your Environment

Executable Version
lerna --version 5.4.2
npm --version 5.4.2
node --version 8.7.0
OS Version
macOS Sierra 10.12.6
@evocateur
Copy link
Member

When working with lerna-managed packages, running npm commands directly in a managed directory (packages/* be default) is not guaranteed to work. It is not an npm bug, either, because lerna bootstrap is doing special things to the package.json when installing (to workaround the local packages, basically).

Currently, removing a dependency in a lerna-managed package requires manual editing of package.json and re-running lerna bootstrap from the root. (contrary to the best practice, which is indeed npm rm/uninstall)

In the future I hope to add a lerna remove subcommand that streamlines this process.

@jennasalau
Copy link
Author

Hmm you would also have to manually remove it from the package-lock.json file and the bloody reference gets entwined everywhere. Its actually a nightmare removing dependencies from a lerna managed package. I also think you should make it more clear in your docs that we are not meant to be using npm in managed packages. I had no idea.

Anyway, as a work around for anyone else experiencing this issue:

You need to temporarily change the sibling references in package.json to use the local path feature. So given the dependency example I gave above:

Change module-a package.json (The one you want to uninstall a dependency on)

From:

{
    "name": "module-a",
    "version": "1.0.0",
    "dependencies": {
        "dependency-a": "^1.0.0",
        "module-b": "^1.0.0",
    }
}

To:

{
    "name": "module-a",
    "version": "1.0.0",
    "dependencies": {
        "dependency-a": "^1.0.0",
        "module-b": "file:../module-b",
    }
}

Then run the local npm uninstall. After which you must change it back otherwise lerna will hang.

@evocateur
Copy link
Member

@jennasalau My apologies, I forgot a step. I have been using --hoist so long, I forgot the patterns when npm actually installs stuff in every package directory (which is pretty slow compared to lerna bootstrap --hoist, even with zippy npm these days).

Anyway: Run lerna clean --yes --scope module-a before re-running lerna bootstrap.

The normal behavior of npm recognizing changes to package.json and manipulating package-lock.json to match will be restored when lerna clean nukes the node_modules. Turns out we have an over-eager optimization in lerna bootstrap that is attempting to save time avoiding a "no-op" install, and we're not respecting npm's ability to also make that judgement (and remove the deleted dependency).

Once again, my apologies. Thank you for having the patience to document a workaround! We (I, actually) could really use help implementing the lerna upgrade <dependencyName> and lerna remove <dependency> subcommands. Even documentation would be appreciated.

@evocateur evocateur reopened this Jan 23, 2018
@evocateur evocateur added this to the v3.0.0 milestone Jan 23, 2018
@Magellol
Copy link

Magellol commented Jan 24, 2018

@evocateur I'd be happy to help improving the documentation. I've been facing similar issues when removing or upgrading a dependency comes into the game. Although, I'm not sure what are the current best practices for removing and upgrading. If you could provide some bullet points of what needs to be done, I can come up with some documentation for them.

@evocateur
Copy link
Member

evocateur commented Jan 25, 2018 via email

@aweber1
Copy link

aweber1 commented Mar 6, 2018

Thanks for the bullet points! For the "remove", however, I ended up having to do this:

(using example module name "my-module")

  • Edit the my-module/package.json, removing the dependency from either devDependencies or dependencies
  • lerna clean --yes --scope my-module
  • lerna bootstrap in the root

using v2.9.0 and not using hoisting

@evocateur
Copy link
Member

@aweber1 Thanks, that's good to know. I kinda dry-coded my bullet points 😅

I'm planning on implementing lerna remove and lerna upgrade, since lerna is now a monorepo itself and the pain is felt directly.

@kamleshchandnani
Copy link

Teaching people in a team to run multiple command to just remove one package is an extra overhead 😢. Is it in plan to implement this anytime soon? @evocateur

@evocateur
Copy link
Member

@kamleshchandnani Well, there is a "help wanted" tag on this issue. I don't have many spare cycles these days, so we're at the mercy of folks pitching in to help implement these commands.

@stale
Copy link

stale bot commented Mar 18, 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 Mar 18, 2019
@stale stale bot closed this as completed Mar 25, 2019
@dhruvdutt
Copy link

@evocateur Can you please keep this open?

@evocateur
Copy link
Member

The stale bot seems to be disregarding my commands. Such is the inevitable end with robots, it seems.

@evocateur evocateur reopened this Mar 26, 2019
@stale stale bot removed the stale label Mar 26, 2019
ghinks added a commit to ghinks/epl-ml-mono-repo that referenced this issue Apr 2, 2019
@tommedema
Copy link

tommedema commented May 6, 2019

Coming back to lerna + npm from yarn workspaces this is a rather big surprise. Uninstalling/installing in packages seems like such a core task of a mono repo manager.

Most annoying is to have to update package.json files manually, lookup version numbers, etc. npm install does this automatically for you but using lerna renders this unusable

@entrptaher
Copy link

Manually linking local packages has become a pain.

@evocateur
Copy link
Member

I dunno, I consider managing packages a core competency of a package manager, which Lerna is not. pnpm has great support for workspaces, you might check it out.

@JamesHenry JamesHenry added the scope: package management Issues with the bootstrap/add/link commands that relate to package management label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: package management Issues with the bootstrap/add/link commands that relate to package management
Projects
None yet
Development

No branches or pull requests

9 participants