'npm installs dependencies in a wrong dir

I created a node project that has a workspace, the project structure looks like:

/package.json

{
 "name": "root",
  "workspaces": ["./child"]
}

/child/package.json

{
  "name": "child",
  "dependencies": {
    "@angular/compiler": "^13.1.2",
    "@angular/router": "^13.1.2"
  }
}

when running npm install it installs @angular/compiler in the root node_modules dir which is the expected behavior. but it installs @angular/router in child/node_modules, it should be installed in the root node_modules

also, the dependencies of it such as rxjs are installed in the child dir even no other versions of the same packages

the project is created in a clean and empty folder, and I cleared the npm cache

minimal reproduction



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source