nodejs / corepack

Zero-runtime-dependency package acting as bridge between Node projects and their package managers
MIT License
2.31k stars 146 forks source link

Usage Error: This project is configured to use yarn #424

Open cdtut opened 3 months ago

cdtut commented 3 months ago

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.

arcanis commented 3 months ago

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.

cdtut commented 3 months ago

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

arcanis commented 3 months ago

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.

cdtut commented 3 months ago

can only make trivial assumptions about it

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

drazisil commented 1 month ago

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