'vue create xxx' - nothing happens - vue.js

I have installed the latest Vue CLI, with npm install -g #vue/cli#next, having uninstalled the previous 'vue-cli'. Now when I try and create a Vue application with e.g. vue create vue3-todo, nothing happens. The command quickly executes without error (but without any prompts), and nothing is created - the directory remains empty.
Clearly something is not right with my Vue CLI installation. Any suggestions as to what the issue might be and how I can clean things up?

I would start with running this to uninstall:
npm uninstall -g vue-cli
Then check my node version. It's recommended to use node v10+ for the latest CLI.
I'd probably do a system restart just because and then reinstall:
npm install -g #vue/cli

I have got to the bottom of this. This is under Windows 10, and I noticed there was a an entry of 'C:\Program Files\nodejs' in the PATH environment variable (under 'System variables'). I looked in that directory, and sure enough, there were a bunch of 'vue*' files. I deleted these and now when I call 'vue' I get the current version as I should. Clearly these were taking precedence over the versions in my AppData/Roamin/npm directory.
I have no idea why these files were there in the first place. I am hoping that having deleted them I do not break anything.

Related

NVM breaks sporadically because of resetting PREFIX environment variable

The Problem
I am trying to run a react-native iOS application from the CLI. This has not been a problem in the past, but haven't developed in react-native for over 6 months. Last week in about 40% of the cases when a (zsh) terminal is opened nvm breaks because of the environment variables. This could happen whether I open the terminal myself, or when VSCode opens a new terminal for the metro bundler. Running from Xcode always works. Closing all zsh terminals and then opening a new one seems to resolve the issue. Additionally, it happens (more) often in the terminal that is opened by VSCode for the metro bundler than when I open the terminals myself. Lastly, the issue seems to 'stick' once it starts occurring I need to close all terminals for the error to be resolved.
Error that is shown
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
What I have tried
Changing environment variables
1.1 When the zsh terminal does NOT show the error:
I tried running npm config delete prefix, in hopes of changing the config so that the issue does not pop up anymore. I can't run this command when the error is shown, because I have no access to node or npm.
1.2 When the zsh terminal does show the error:
I can 'fix' the terminal by unsetting the PREFIX variable with unset PREFIX and then asking nvm to use a version of node. However this only fixes that particular instance of the terminals. The only sure fire way is to close all terminals.
unset PREFIX
nvm use v14.15.0
Updating react-native
Speaks for itself, a colleague mentioned that it might be caused by a bug in react-native. Did not resolve the issue unfortunately.
Conclusion
It seems as though something (re)triggers setting the PREFIX environment variable when I try to run the react-native iOS project. I am honestly completely lost as to what might be causing this and any help would be truly appreciated.
I had this issue too, as have others.
Are you using yarn or npm to run the React Native CLI? If so, and these were installed with Homebrew, these might be conflicting with your nvm installed node. Try removing these:
brew uninstall yarn
brew uninstall npm
This should leave behind the version of npm that was installed with nvm, check this by running:
which npm
This should return a path pointing to your local .nvm installation. If it shows /usr/local then it was not removed correctly, you might need to follow the npm removal instructions.
Once this is done, if you use yarn then install it with npm:
npm install -g yarn
Run the React Native CLI once again, it should now work.
More details on this resolution: https://github.com/nvm-sh/nvm/issues/1645#issuecomment-850376572

npx from command line does not find imports?

I'm trying to run a simple hello.ts script from command line. This works if the script has no dependencies:
npx ts-node hello.ts
But as soon as I start adding some dependencies...
import _ from 'lodash';
console.log('hello');
It fails:
Cannot find module 'lodash' or its corresponding type declarations.
It keeps failing even if I install the dependencies globally. So how do I tell npx (or ts-node for that matter) to consider globally installed dependencies?
Update
Using Node 16.9.1 (upgraded via Version Lens). The error seems to have disappeared after uninstalling/reinstalling the imported libraries a few times.
If you're using npm >=1.0, you can use npm link to create a local link to a package already installed globally. (Caveat: The OS must support symlinks.)
IE: npm install -g lodash && npm link lodash
However, this doesn't come without its problems.
npm link is a development tool. It's awesome for managing packages on your local development box. But deploying with npm link is basically asking for problems, since it makes it super easy to update things without realizing it.
As an alternative, you can install the packages locally as well as globally.
For additional information, see:
https://nodejs.org/en/blog/npm/npm-1-0-link/
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
Are you using the n package by any chance? I used n to change from a newer version of node (16.2.0) to an older version of node (12.13.0), ran npm i and npx failed with a different error.
Using n to change back to 16.2.0 seems to have resolved the issue so I'm thinking perhaps it was an issue with package-lock.json or such

nvm installing yarn either on a Node version folder or in one folder regardless of Node version?

It is a bit strange that on my MacBook Air, npm installed yarn on
$ which yarn
/Users/peter/.npm-global/bin/yarn
but on my other iMac, it is installed on a "per Node version folder":
$ which yarn
/Users/peterimac/.nvm/versions/node/v16.0.0/bin/yarn
Which one is more correct, and should I and how do I adjust the other Mac back to the "correct" mode? But on the iMac, it is strange that if I do
yarn use 16
yarn build
and then it says to use yarn global add serve and then serve -s build but it kept on saying serve does exist no matter how I source ~/.profile and source ~/.zprofile. I have to npm i -g serve for it to exist.
Also, on the first Mac, the yarn and serve also do not need to be installed for any different versions of Node. The same version of yarn and serve seemed to be used no matter which version of Node I change to using nvm use 14 or nvm use 16. So I am not sure if this is the correct behavior.
Is one Mac more correct than the other, and how to fix it back to the correct way and what about the serve not installed issue?
I found part of the answer: if your yarn is at
/Users/peter/.npm-global/bin/yarn
that means some time in the past, you have set .npm-global to be a one and only path... and that would conflict with nvm. So remove that line from your ~/.npmrc, and also remove the .npm-global text or line from your ~/.profile, and .zprofile, .bashrc, .zshrc, if any.

Why is preact not getting recognized in the terminal even after installing it?

I have installed Preact but it’s not getting recognized in the terminal. First, I went to the official website of PreactJS. The doc says that I have to run npm install -g preact-cli. As I am using Yarn, I ran yarn global add preact-cli. It was installed successfully but with a lot of warnings. Then I ran preact create default first-preact-app. But it's showing an error that "The term 'Preact' is not recognized as a name of a cmdlet, function, script file or executable program."
I have tried force cleaning the cache and reinstalling preact-cli. But it doesn't work. Two of the warnings are that preact and preact-render-to-string have unmet peer dependency. So, I have installed them also. But it still doesn't work.
I have tried running npm and experimented with the commands also. But it didn't work. So, how can I fix the problem?
I have run these commands using Powershell and Git bash on Windows 10. I am trying to install Preact 10.5.12 using Yarn 1.22.5. And a point to be noted, I tried running yarn dlx but it returns an error that "command not found". And when the installation of preact and preact-render-to-string gets finished, yarn gives and warning that they have no binaries.
EDIT: Perhaps, it was a problem with Windows. The problem has gone after reinstalling it.
Your problem almost certainly is that preact-cli was not on your PATH - a list of programs that are globally accessible.
For what it's worth, we don't recommend installing globally. The site may still say that but the repository correctly recommends using npx instead.

Error: option 'name' clashes with existing property 'name' on Command

Some context: I've recently been trying to update a react native project that uses expo, since I have not worked on the project for about four months. I believe I finally was able to successfully upgrade the project as expo is starting. The issue is that I am now having some trouble with some of the newer modules I just installed with npm. This error seems to be coming from me not knowing how to use the commander module. Additionally, I do not believe that I have a thorough understanding of modulues in react native/expo. I am using ubuntu 20.04 via windows terminal.
Error:
I did go to the website mentioned in the error. I believe that this link - https://github.com/tj/commander.js#avoiding-option-name-clashes - is what will solve my problem. However, I am confused as to where I should put the example file and how to use it.
I am not very well versed in modules for react native/expo and it is quite possible that I do not need to use this module (I thought that installing it would make my react native program run, but that does not seem to be the case).
Thus, I am looking for advice on either how to use this module, or on whether or not I should be using these modules (after updating node and then expo, the following modules could not be found every time I ran npm start, so I decided to install them using sudo npm install module_name -g since some other stackoverflow/github pages recommended that):
fs-extra
terminal-link
chalk
getenv
commander
#expo/xdl
Any help would be appreciated, and I would be happy to provide any more information that would be relevant.
I was not able to figure out a way to make the project work with the above modules. So, I followed the advice of a post I made on the expo forums (I posted similar context there and also the answer that I wrote below).
If you do not want to click the link, here are the steps below:
Basically, I uninstalled expo using the following command: npm -g uninstall expo-cli --save && yarn global remove expo-cli. Then I proceeded to remove the .expo folder from my home directory. More details on these two steps can be found here.
After that, I reinstalled expo using npm install --global expo-cli, from the expo documentation, in the install section.
Then I closed my terminal, reopened it, and ran expo whoami. The command returned recommending an update, so I followed the provided update command (which I believe was just npm install --global expo-cli again).
I closed the terminal, reopened it, and ran expo whoami again. This time I was just met with "you are not logged into expo" (or something along those lines). So, everything seemed up to date.
I then went to project and ran npm start and it worked fine.
Note: You may need to use sudo for any uninstall and install commands above (your terminal will likely tell you if you do).
Note Clearing cache for npm and yarn may take some time. Additionally, the first time you run npm start may also take some time. I'd say all in all this took about two to three hours, but my computer is also not the best.