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.packageManager=auto incorrectly assumes yarn as package manager for running tasks #170101

Open
Zelgadis87 opened this issue Dec 27, 2022 · 6 comments · May be fixed by #243250
Open

npm.packageManager=auto incorrectly assumes yarn as package manager for running tasks #170101

Zelgadis87 opened this issue Dec 27, 2022 · 6 comments · May be fixed by #243250
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues
Milestone

Comments

@Zelgadis87
Copy link

Type: Bug

I have a fairly standard PNPM project, for which I have configured a few VSCode tasks:

{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "bar",
			"type": "npm",
			"script": "bar"
		}
	]
}

When VSCode is set with npm.packageManager=auto, it incorrectly assumes that tasks should be run using yarn.
Since the project uses corepack and specifies a packageManager in package.json, using yarn results in an error:

* Executing task in folder foo: yarn run bar 
Usage Error: This project is configured to use pnpm
$ yarn ...
 *  The terminal process "cmd.exe /d /c yarn run bar" terminated with exit code: 1. 

This for me doesn't make much sense, because:

  • in the project folder there is a package.json, configured with "packageManager": "pnpm@7.9.3" (using corepack)
  • in the project folder there is a pnpm-lock.yaml and a pnpm-workspace.yaml files, which should correctly hint to the right package manager
  • there is no trace of a yarn.lock or any other yarn-specific files or configurations.
  • yarn is installed globally (via corepack shims) but so is npm and pnpm

If the auto detection for PNPM failed, I'd expect to at least fallback to NPM.
Using npm.packageManager=pnpm of course works fine.

VS Code version: Code - Insiders 1.75.0-insider (6ed4d43, 2022-12-23T05:21:57.802Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Sandboxed: Yes

System Info
Item Value
CPUs Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz (4 x 3504)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 15.95GB (5.19GB free)
Process Argv ..\cronicle\ --crash-reporter-id 2a3507f6-d0a2-424d-8827-2b26df7c63ff
Screen Reader no
VM 0%
Extensions (5)
Extension Author (truncated) Version
vscode-eslint dba 2.2.6
gitlens-insiders eam 2022.12.2304
intellicode-api-usage-examples Vis 0.2.6
vscodeintellicode Vis 1.2.29
markdown-all-in-one yzh 3.5.0
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30422396
pythontb:30258533
vsc_aacf:30263846
pythonptprofiler:30281269
vsdfh931:30280409
vshan820:30294714
pythondataviewer:30285072
vscod805cf:30301675
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30404738
cppdebug:30492333
vsclangdf:30492506
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30618038
pylantcb52:30590116
pyindex848:30611229
nodejswelcome1:30587009
pyind779:30611226
vscrpc:30624061
pythonsymbol12cf:30622697
fim-prod:30623723

@meganrogge meganrogge added bug Issue identified by VS Code Team member as probable bug tasks Task system issues labels Jan 4, 2023
@meganrogge meganrogge added this to the Backlog milestone Jan 4, 2023
@fdesforges
Copy link

I have the same issue using npm workspaces, and opening vscode not from the root of the monorepo.

running debug task from package.json try to use yarn.

npm.packageManager=npm solve the issue

Vscode 1.74.3

@lawvs
Copy link
Contributor

lawvs commented Feb 21, 2023

Blame to

if (typeof findWorkspaceRoot(pkgPath) === 'string') {
return { isPreferred: true, hasLockfile: false };
}

The find-yarn-workspace-root package assumes that it is being used in a yarn project and only checks for the packageJson.workspaces field.

However, this field also exists in pnpm and npm projects.

As a result, this means that all pnpm projects will be detected as yarn projects.

Also related to #139654

@wscales10
Copy link

I just ran into this. I expect it is the same issue as #159465. The workaround I used was changing

"type": "npm",
"script": "compile",

to

"type": "shell",
"command": "npm",
"args": ["run", "compile"],

@rotu
Copy link

rotu commented Aug 24, 2023

Yeah this is pretty insane behavior.

It would be very sensible to instead detect the package manager using the project's package.json "packageManager" key if present.

@Yimiprod
Copy link

Reproducing the same behavior.

@rotu rotu linked a pull request Mar 11, 2025 that will close this issue
@rotu
Copy link

rotu commented Mar 12, 2025

It would be very sensible to instead detect the package manager using the project's package.json "packageManager" key if present.

Not sure if this recommendation is still current given the churn around corepack. It seems maybe the package manager key was migrated to devEngines.
https://docs.npmjs.com/cli/v11/configuring-npm/package-json#devengines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants