corepack icon indicating copy to clipboard operation
corepack copied to clipboard

Usage Error: This project is configured to use yarn

Open cdtut opened this issue 1 year ago • 8 comments

If you have pnpm and yarn projects try change to yarn_project and run pnpm --dir pnpm_project or change to pnpm_project and run yarn --cwd yarn_project. There is error Usage Error: This project is configured to use yarn. Should be no error to use like this.

cdtut avatar Mar 11 '24 15:03 cdtut

That's the expected behaviour. See the documentation:

COREPACK_ENABLE_STRICT can be set to 0 to prevent Corepack from throwing error if the package manager does not correspond to the one defined for the current project. This means that if a user is using the package manager specified in the current project, it will use the version specified by the project's packageManager field. But if the user is using other package manager different from the one specified for the current project, it will use the system-wide package manager version.

You can also explicitly call corepack yarn ... on pnpm projects (or corepack pnpm ... on Yarn projects) to bypass this check.

arcanis avatar Mar 11 '24 16:03 arcanis

Even with no COREPACK_ENABLE_STRICT the error should not happen if pnpm --dir or yarn --cwd point to location outside current project.

cdtut avatar Mar 11 '24 17:03 cdtut

Corepack has no knowledge of what the underlying package manager CLIs look like, and can only make trivial assumptions about it. If you want a similar behaviour, you'll need to cd into the target directory and run the command from there.

arcanis avatar Mar 11 '24 17:03 arcanis

can only make trivial assumptions about it

Can be trivial if --dir is on pnpm or --cwd is on yarn then skip warning.

cdtut avatar Mar 11 '24 20:03 cdtut

In my case, the error occurred because I had pnpm in the script that I was trying to run with yarn.

drazisil avatar May 12 '24 12:05 drazisil