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?
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.
In general, as of 2021, there is no equivalent for npx
Feature was requested in yarn, but went not really solved
https://github.com/yarnpkg/yarn/issues/3937
So package developers need to think for both npm and yarn users.
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 ...
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
Yarn now supports create cli as following
yarn create [your-cli-name] [..arugments]
for eg. yarn create expo-app hello-world
Related
Can I use npx together with a pnpm install?
It doesn't seem to work and pnpx fetches remote dependencies, it seems more like npm create.
Is there a way to use npx with pnpm to execute local binaries or is there a different pnpm equivalent?
The are are two keys uses of npx.
Running executables inside your downloaded dependencies
For example npx jest.
The pnpm equivalent is pnpm exec jest.
Running executable commands in packages you want to download transiently
For example npx create-react-app my-app.
The pnpm equivalent of this is pnpm dlx create-react-app my-app.
Note: There used to be a pnpx command, but it has been deprecated (details here).
I'm trying to configure Bitbucket CI/CD for cypress testing on my vue app which uses yarn for package management.
Is there any way to start server in background by yarn?
Thanks in advance
Welcome to stackoverflow Alessandra.
yarn start command is equivalent to npm run start
However if you have created a custom command in your package.json for start:ci you can use equivalent yarn command as yarn start:ci
You can also use yarn run start:ci however its run is redundent here. Please see this documentation
https://classic.yarnpkg.com/lang/en/docs/cli/run/
I am trying to migrate from NPM to Yarn for the sole reason of getting rid of 'node_modules' folder.
I am trying to use CRA tool. However, on CRA it advises to use yarn create, which is not a command found in Yarn 2 documentation. After some research I found out that I should use yarn dlx command, which is equivalent to npx.
The problem is that to use yarn dlx, I must have Yarn 2 first. Yarn 2 requires that I install it locally in my project directory. This way, I am forced to have a second layer of folder structure.
I want to create-react-app in a folder on my Desktop called myApp. But, I need to create myApp folder to install Yarn 2 before I can even start using dlx to run create-react-app.
Am I missing something?
Thank you.
I faced the same situation recently... my solution was:
yarn create react-app myApp (yes, is yarn 1.22 in my case)
rename the package.json for a while
yarn init -2 # this will create another package.json
merge the old package.json with the newly created one
yarn install
now you can configure PnP as is described on the Yarn documentation or...
you can create directly whit npx:
npx create-react-app your-app-name --use-pnp
Yes, for now, you have to use the second layer of the folder structure.
Assuming you have the latest version of Node 14.x, 16.x or any higher versions, the minimal instructions are the following.
Prerequisites:
Ensure that corepack is enabled via corepack enable command. This needs to be done only once.
Steps:
mkdir enclosing; cd enclosing - to create enclosing directory
yarn set version stable - to use latest stable Yarn version in the eclosing directory and all of its subdirectories
rm package.json - delete package.json in the enclosing directory, generated by the previous command to not confuse Yarn that the enclosing directory is the root of the project.
yarn create react-app my-app - the project will be generated with Yarn 3 and by default will use PnP install scheme
cd my-app; yarn set version latest - to attach Yarn 3+ to my-app project
Optional step, if you want to use node_modules install scheme with Yarn 3+, inside my-app run yarn config set nodeLinker node-modules
After that, you can move out my-app anywhere and delete enclosing directory.
In order to simplify all this into yarn dlx create-react-app I have opened pull request to create-react-app, please place a thumb up emojo for it here:
https://github.com/facebook/create-react-app/pull/12366
Let's say you're running this command:
npx gulp
npx will search for gulp within node_modules/.bin, and if it doesn't find it there, it will use a central cache. If it is missing, npx will install it.
How do I clear the central cache to force npx to reinstall gulp in this case?
On macOS (and likely Linux) it's ~/.npm/_npx, you can drop it with:
rm -rf ~/.npm/_npx
On Windows it should be %LocalAppData%/npm-cache/_npx
Either way, you can find npm’s cache by running npm config get cache and then finding an npx folder in there.
I needed to do this, due to an error in create-react-app saying 'We no longer support global installation of Create React App.' despite there being no global install. It was stuck in the npx cache, and I removed it like this
npx clear-npx-cache
Previously, when I had tried using react-native we were told to use react-native run-ios to run the project from the command line. Now, the instructions say to use npx react-native run-ios from the command line.
What in the benefit of using npx. Does using npx change how the project is compiled? If I sometimes use npx and sometimes neglect to use it will it mess anything up in my project?
Check this answer more about of npx
react-native supported and recommended to use npx start from react-native#0.60.0.
The benefit of using npx is don't need to install react-native-cli tools globally. Check the below example of using npx and not for the react-native project.
### Using npx ###
﹩ npx react-native init <SimpleProjectName>
### Without using npx ###
﹩ npm i -g react-native-cli
﹩ react-native init <SimpleProjectName>
Both react-native-cli and npx react-native are should not use in one project. The official docs said before starting a new project:
If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues.