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] npm workspaces issue when using different versions of the same package #4990

Closed
2 tasks done
Maxim-Mazurok opened this issue Jun 4, 2022 · 6 comments
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@Maxim-Mazurok
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

"testing jest-26"
28.1.0 <<< unexpected

"testing jest-28"
28.1.0

Expected Behavior

"testing jest-26"
26.6.3 <<< expected

"testing jest-28"
28.1.0

Steps To Reproduce

  1. git clone https://github.com/Maxim-Mazurok/npm-workspaces-repro
  2. Use node v18.3.0 and npm@8.12.1: nvm i 18.3.0 or nvs add 18.3.0 && nvs use 18.3.0
  3. npm ci
  4. npm test

Environment

  • npm: 8.12.1
  • Node.js: 18.3.0
  • OS Name: Windows 11
  • System Model Name: X570 GAMING X
  • npm config:
; "user" config from C:\Users\maxim\.npmrc
   
registry = "https://registry.npmjs.org/" 

; node bin location = C:\Users\maxim\AppData\Local\nvs\node\18.3.0\x64\node.exe
; node version = v18.3.0
; npm local prefix = C:\Users\maxim\npm-test
; npm version = 8.12.1
; cwd = C:\Users\maxim\npm-test
; HOME = C:\Users\maxim
; Run `npm config ls -l` to show all defaults.
@Maxim-Mazurok Maxim-Mazurok added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jun 4, 2022
@Maxim-Mazurok
Copy link
Author

Workaround:

Use jest programmatically: node -e "console.log(require('jest').getVersion())"

See Maxim-Mazurok/npm-workspaces-repro@eed5ec8

@fritzy
Copy link
Contributor

fritzy commented Jun 29, 2022

I was able to reproduce this on Windows, but not on other platforms.

@fritzy fritzy added Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Jun 29, 2022
@fritzy
Copy link
Contributor

fritzy commented Jun 29, 2022

The %PATH% is generated correctly for each script. The %CD% is correct for each script.
\node_modules\jest\package.json is 26.x.x
\jest-26\node_modules\jest\package.json is 28.x.x

But when executing \node_modules\.bin\jest.cmd from any other path other than the project root, it'll resolve jest@28 rather than jest@26

@siemhesda siemhesda self-assigned this Feb 8, 2024
@siemhesda
Copy link
Contributor

Running npm ci on the root folder adds node _modules for the root folder and for jest-28 folder but does not do the same for the jest-26 folder.

When I run npm ci in the jest-26 folder to generate the node_modules and redo the npm test on the root folder, I get the expected value for jest-26 but an error for jest-28 as shown below.

> test
> npm test --workspaces


> test
> echo "testing jest-26" && jest --version

"testing jest-26"
26.6.3

> test
> echo "testing jest-28" && jest --version

"testing jest-28"
node:internal/modules/cjs/loader:1051
 throw err;
 ^

Error: Cannot find module 'jest-cli/bin/jest'
Require stack:
- C:\Users\user\Documents\npm-workspace-repro\jest-28\node_modules\jest\bin\jest.js
   at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
   at Module._load (node:internal/modules/cjs/loader:901:27)
   at Module.require (node:internal/modules/cjs/loader:1115:19)
   at require (node:internal/modules/helpers:130:18)
   at Object.<anonymous> (C:\Users\user\Documents\npm-workspace-repro\jest-28\node_modules\jest\bin\jest.js:12:3)
   at require (node:internal/modules/helpers:130:18)
   at Object.<anonymous> (C:\Users\user\Documents\npm-workspace-repro\jest-28\node_modules\jest\bin\jest.js:12:3)
   at Module._compile (node:internal/modules/cjs/loader:1241:14)
   at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
   at Module.load (node:internal/modules/cjs/loader:1091:32)
   at Module._load (node:internal/modules/cjs/loader:938:12)
   at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
 code: 'MODULE_NOT_FOUND',
 requireStack: [
   'C:\\Users\\user\\Documents\\npm-workspace-repro\\jest-28\\node_modules\\jest\\bin\\jest.js'
 ]
}

Node.js v20.7.0
npm ERR! Lifecycle script `test` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: jest-28
npm ERR!   at location: C:\Users\user\Documents\npm-workspace-repro\jest-28

These findings bring about the questions.

If npm ci on a root folder is supposed to install packages on sub folders, then why did it do it for just one sub folder and not the other?

@siemhesda
Copy link
Contributor

siemhesda commented Feb 21, 2024

After thorough testing, we identified the issue does not exist in the new version of node and npm. By switching to node 18.18.2 or higher versions, you can achieve the expected results.
img

cc@wraithgar

@milaninfy
Copy link
Contributor

This looks like it's fixed as of 10.8.1. Please updated npm.

~/workarea/rep/npm-workspaces-repro $ npm test

> test
> npm test --workspaces


> test
> echo "testing jest-26" && jest --version

testing jest-26
26.6.3

> test
> echo "testing jest-28" && jest --version

testing jest-28
28.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

5 participants