Is there any Yarn equivalent of npx preact create?
Asked Answered
G

6

24

I am trying to run the preact create command using Yarn. It's simple to run preact create ..... ..... or npx preact create ... ..... It works fine and both of the commands use npm. But I am trying to run the command using Yarn. I have tried the following commands but nothing works. The error says "couldn't find a package.json file in path".

yarn preact create .... ....

yarn dlx preact create .... ....

yarn preact-cli create .... ....

yarn dlx preact-cli create .... ....

So, what should I do to run the command using Yarn. One alternative maybe is running the command using npm and then running yarn install and then running npm uninstall. But what's the actual way?

Grison answered 5/3, 2021 at 16:29 Comment(0)
M
25

There is no Yarn equivalent for npx. The Yarn team thought npx was enough.

That being said, we support creating a new Preact CLI project with Yarn through the --yarn flag.

npx preact-cli create ... --yarn

https://github.com/preactjs/preact-cli#cli-options

Please do note that when using Preact CLI via NPX, you do need to use preact-cli. npx preact gives you the Preact library.

Miltie answered 13/3, 2021 at 11:26 Comment(6)
Thank you @Miltie for this useful answer. But the above line of code doesn't work. It still uses npm to install the dependencies. But thank you for informing me about the --yarn flag. I used it while running preact create ...... ...... --yarn and it works fine. Though preact create isn't an alternative to npx.Grison
You're saying npx preact-cli create ... --yarn doesn't install using yarn? Mind raising an issue in our tracker? I can't reproduce and I don't see how that could happen but it's clearly something we need to address.Miltie
Yeah, it's not working. Well, I'll open an issue in the github repo of preact.Grison
Make sure it's Preact-CLI, not Preact. Different things. But I'll take a look there.Miltie
Hmm.. I tried running the command again before raising a issue in issue tracker. But now I see that it uses npm at first to install preact-cli (as I didn't install preact-cli using yarn). Then it uses to yarn to create the preact-app. So, it's normal I think and I am not raising an issue..Grison
Ah, yeah, that's normal. NPX, if you didn't know, is a way or globally installing an app with NPM that is not accessible, i.e., you can't actually use it outside of NPX. The install will then be deleted overtime when the cache is cleared. NPX is used to setup Preact-CLI, as Yarn does not offer an equivalent, but we use the package manager of your choice for installing the dependencies into your new project.Miltie
S
14

UPDATED: there is yarn dlx in v2

Run a package in a temporary environment.

https://yarnpkg.com/cli/dlx

Feature was requested in yarn https://github.com/yarnpkg/yarn/issues/3937

So package developers need to think for both npm and yarn users.

Stonework answered 22/7, 2021 at 11:18 Comment(2)
This should become the new accepted answer now that yarn 2 (aka yarn berry) has come out.Gagger
It should not, as it would not solve the user's problem. The --yarn flag is what determines the package manager for Preact-CLI (though that tool is now unmaintained).Miltie
M
4

You can use ynpx as an equivalent.

yarn global add ynpx

Then do your npx commands as normal, using ynpx in place of npx

eg.

ynpx preact create ...
Mononucleosis answered 11/11, 2022 at 11:24 Comment(0)
O
3

For a TL;DR answer from the thread mentioned above. You can find the following.

npx performs no operations which clash with people using other package managers [...] So you could say npx is ypx, unless you feel really strongly about cache-sharing, which is a pretty thing. For the probable reasoning of not creating a ypx specific command

Ozellaozen answered 2/2, 2022 at 15:25 Comment(0)
G
-1

Yarn now supports create cli as following

yarn create [your-cli-name] [..arugments]

for eg. yarn create expo-app hello-world

Grazier answered 26/8, 2022 at 17:22 Comment(3)
This is not relevant for preact-cli. yarn create and npm init only work with packages prefixed with create-, i.e,, create-foo -> yarn create foo. Preact-CLI, at this time, does not offer a package in this format so your answer is wrong in context.Miltie
correct, my answer is more general and not relevant to preact-cli.Grazier
If it's not relevant for preact-cli then it's not relevant to this question. This question is about how to initialize a preact-cli project with yarn.Miltie
A
-1

One alternavite would be using vite with yarn.

yarn create vite your-project --template=preact
Advisee answered 30/4, 2023 at 6:43 Comment(4)
This has nothing to do with the question. The user was asking how to create a new Preact-CLI project with Yarn; Vite is a separate tool entirely.Miltie
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBenner
@rohit-gupta, rschristian True, this answer doesn't address the preact-cli issue, Only gives alternative way to create preact app using yarn and viteAdvisee
That's not how this site works. Do not provide answers that you know do not address the issue the OP is facing. It provides no value.Miltie

© 2022 - 2024 — McMap. All rights reserved.