2

So with the release of NPM 7.0.0, I am trying to figure out how to use NPM instead of Yarn Workspaces with Lerna.

In Yarn it is possible to do yarn add packageName --dev -W to add the dependency to the root level package.json. How can I do that with NPM?

RobC
  • 22,977
  • 20
  • 73
  • 80
AngularDebutant
  • 1,436
  • 5
  • 19
  • 41

2 Answers2

0

npm does not really reflect how yarn works with regards to workspaces.

Yarn expects you to explicitly install deps, npm does not. (actually running npm install at any other level than the workspace root might and will break things when using npms workspace implementation)

So to add a package (at root or not) you should manually edit the package.json at the level where you want to add the dependency and then run npm install.

Example:

  1. You want to add concurrently to your root folder and use it to run multiple scripts... concurrently
  2. You do not add it to a workspace within the workspace, since it does not actually belong in any of them
  3. Manually edit package.json in your workspace root folder
  4. Add "devDependencies": { "concurrently": "^5.3.0" },
  5. run npm install in your workspace root
  6. concurrently is now in node_modules and can be executed in your workspace root
Tor Raswill
  • 149
  • 5
-2

You could do this like this -

npm install packageName --dev
Akash
  • 762
  • 7
  • 25
  • 1
    `-g` flag does global install which isn't what the OP was looking for. Correct syntax would be `npm install packageName --sav-dev` or `npm i packageName -D` – Free Url Apr 19 '21 at 19:24