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

[BUG] Can't install new dependencies into workspace package with workspace dependencies #2035

Closed
justinfagnani opened this issue Oct 24, 2020 · 10 comments
Labels
Enhancement new feature or improvement Release 7.x work is associated with a specific npm 7 release

Comments

@justinfagnani
Copy link

Current Behavior:

npm i some-package fails if run in a workspace package that depends on another workspace package. The error is that the other workspace package is not found in the registray:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/other-package - Not found

Here other-package is a private package in the same workspace.

You also can't add a dependency manually and run npm i in the root of the workspace due to #1984

So there appears to be no way to add new dependencies in a workspace, aside from deleting the top-level node_modules folder and package-lock.

Expected Behavior:

npm i inside a workspace package should update the package.json file and install the dependency.

Steps To Reproduce:

  1. In a workspace with packages a and b, with a depending on b
  2. Do an initial install at the workspace root to set everything up
  3. cd to packages/a
  4. Run npm i {some-package}
  5. See error...

Environment:

  • OS: macOS
  • Node: 15
  • npm: 17.0.5
@justinfagnani justinfagnani added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Oct 24, 2020
@protyposis
Copy link

This is probably related to what I described in #2036 (comment). The current answer in #2036 (comment) is that npm install does not support workspace packages yet and we need to edit the package.json manually (which, as you already said, doesn't work: #1984).

@samscodes
Copy link

I have the same issue

@darcyclarke darcyclarke added Enhancement new feature or improvement and removed Bug thing that needs fixing Needs Triage needs review for next steps labels Jan 22, 2021
@darcyclarke
Copy link
Contributor

@justinfagnani we're working on improving the workspace experiences for these types of scenarios this quarter.

trivikr added a commit to trivikr/react-native-get-random-values-peer-deps-test that referenced this issue Apr 7, 2021
@ruyadorno
Copy link
Contributor

Starting from npm@7.14.0 npm install now supports adding dependencies to configured workspaces using the following syntax:

$ npm install <pkg> -w <workspace-name>

It's also possible to install a workspace into another, e.g:

npm init -y
Wrote to <path>/test-new-workspaces/package.json

$ npm init -w packages/a -y
Wrote to <path>/test-new-workspaces/packages/a/package.json

$ npm init -w packages/b -y
Wrote to <path>/test-new-workspaces/packages/b/package.json

$ npm i b -w a

added 2 packages, and audited 5 packages in 723ms

found 0 vulnerabilities

$ npm ls
test-new-workspaces@1.0.0 <path>/test-new-workspaces
├─┬ a@1.0.0 -> <path>/test-new-workspaces/packages/a
│ └── b@1.0.0 deduped -> <path>/test-new-workspaces/packages/b
└── b@1.0.0 -> <path>/test-new-workspaces/packages/b

@craigphicks craigphicks mentioned this issue Sep 12, 2021
1 task
@craigphicks
Copy link

craigphicks commented Sep 28, 2021

@ruyadorno - I found that npm i b -w a would install the external package 'b' from npm.
To get it to work properly the exact version is necessary:

npm i b@1.0.0 -w a

in this case.


EDIT: adding exact procedure to recreate the error when NOT using the exact version, but the commands that @ruyadorno provided. I am using

  • npm 7.21.1
  • node v14.7.4

In an empty folder execute a shell script as follows:

npm init -y
npm init -w packages/a -y
npm init -w packages/b -y
npm i b -w a
npm ls

The output (ending in a error ) is a as follows -

Wrote to /home/craig/tmp/package.json:

{
  "name": "tmp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


Wrote to /home/craig/tmp/packages/a/package.json:

{
  "name": "a",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


Wrote to /home/craig/tmp/packages/b/package.json:

{
  "name": "b",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



added 2 packages, and audited 4 packages in 562ms

found 0 vulnerabilities
tmp@1.0.0 /home/craig/tmp
├─┬ a@1.0.0 -> ./packages/a
│ └── b@2.0.1
└── UNMET DEPENDENCY b@file:/home/craig/tmp/packages/b

npm ERR! code ELSPROBLEMS
npm ERR! missing: b@file:/home/craig/tmp/packages/b, required by tmp@1.0.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/craig/.npm/_logs/2021-10-02T21_45_42_165Z-debug.log

@Brennvo
Copy link

Brennvo commented Oct 1, 2021

@ruyadorno - I found that npm i b -w a would install the external package 'b' from npm. To get it to work properly the exact version is necessary:

npm i b@1.0.0 -w a

in this case.

This works when adding the dependency in the lerna monorepo. I am running into issues, however, when I try installing a tarball that has this internal dependency. For example:

repo/
|__ packages/
|   |__ a/
|   |   |__ package.json
|   |
|   |__ b/
|       |__ package.json
|       |__ b-1.0.0.tgz
|
|__ package.json

If workspace b has a direct dependency on workspace a, when I go to install the workspace b tarball file in another external application (locally), I get a new error related to the node_modules in workspace a.

@craigphicks
Copy link

@Brennvo - Can you show the working commands you used, including the lerna commands?

@iSuslov
Copy link

iSuslov commented Dec 8, 2021

Unbelievable. Look at this.
npm -v //8.1.2

npm init -y
npm init -w packages/a -y
npm init -w packages/b -y

...Everything is OK

npm i b@1.0.0 -w a

added 2 packages, and audited 5 packages in 908ms also works great

npm init -w packages/c -y

Created package c

npm i c@1.0.0 -w a

Added package c to a.

Now magic happens

npm init -w packages/z -y

Created package z

npm i z@1.0.0 -w a
npm ERR! code ETARGET
npm ERR! notarget No matching version found for z@1.0.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:

How is that possible?

It turns out that package name matters when you work with workspaces.

@wraithgar @fritzy @lukekarrys could you please comment on this?

@K4CZP3R
Copy link

K4CZP3R commented Feb 3, 2022

I'm having the same problem; Package with name: a-style-flex inside packages/components/styles/flex is not recognised.

It works only when I change styles in path to style

@iSuslov
Copy link

iSuslov commented Feb 6, 2022

I created separated issue #4379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

9 participants