Can I use NPX with yarn?
Asked Answered
N

1

17

I have a project that I am using yarn for. I've installed all my packages using yarn, I run yarn dev and so on. Now I'm following a tutorial that requires me to use npx to set up a package. - I'm wondering if I can just go ahead with this or if I will end up mixing things up here, as npx, as far as I know, is related to npm ?

Nausea answered 27/9, 2021 at 11:23 Comment(4)
npx does nothing more than invoking a script on a npm repository (which yarn also uses) without actually installing it (globally). It can be used interchangeable with yarn.Clinician
Also you can use yarn instead of npx.Faeroese
Thanks a lot! instead of but also with it ? as in: can I today install everything with yarn, tomorrow use an npx command and then next week use yarn add xxx again?Nausea
I was just wondering if I should do this. I just used npx for npx eslint init. It created a package-lock.json (along with other configs and added dependencies), then I deleted the package-lock.json and ran yarn after to properly install. Seems like it worked without any problems.Akins
B
19

Yes. npx will run the executable from your node_modules directory if it is installed there. If it is not, it will install the executable into a different location. It will not interfere with yarn operations.

With Yarn 2, you can also use dlx. For example:

yarn dlx create-react-app ./my-app

See https://yarnpkg.com/cli/dlx for information and options.

Berga answered 6/10, 2021 at 5:32 Comment(1)
Since i came across this question today, check out yarn dlx <comman> and the blog post of yarn2. Please notice this only works for yarn2 or higher.Jest

© 2022 - 2024 — McMap. All rights reserved.