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

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.

Related

Cannot find module ‘#expo/metro-config’ when trying to start the project with expo cli >= 4.8.0

I recently tried to launch my project on a new computer. I downloaded the source code from its repository and ran npm install to get all the needed packages.
However, when I run npm start or expo start:web, I get the error:
Cannot find module '#expo/metro-config'
I ran npm install #expo/metro-config and the install run without issue, but I still get the “Cannot find module '#expo/metro-config'” error.
The only post I saw regarding this error recommends editing the metro.config.js but I do not use one.
I am on SDK 42, and the project launches fine on my other computer. Any idea what is happening?
FYI, I use to perform this whole operation without any issue until now.
UPDATE:
I ran npm install -g #expo/metro-config and now I get the error Cannot find module 'resolve-from'
So it looks like maybe running npm install -g expo-cli doesn't actually install all the necessary packages? Could it be the issue?
I managed to make it "work" (get other missing packages errors down the line) by reverting to expo-cli 4.7.3. Anything from 4.8.0 and above will cause the error.
Something else is that on a fresh npm install, after running npm install -g expo-cli, if I try to create a project with expo init, I will get the error Error: Cannot find module 'kleur'. Running npm install kleur fix it, but maybe that's also a clue.

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

How to stop angular-cli freezing on "loadRequestedDeps: silly install loadAllDepsIntoIdealTree"?

I am running Windows 8.1 with node version 7.7.3 and npm version 4.1.2.
I have been working on an Angular tutorial without issues. At some point since finishing that tutorial I installed Python. I am not sure if it is related, but I have mentioned it just in case.
Today I am trying to create an Angular application and it hung without completing.
I did some research and it tells me to do this:
npm uninstall -g #angluar/cli
npm cache clean
npm install -g #angular/cli
The last command hangs at this point:
loadRequestedDeps: silly install loadAllDepsIntoIdealTree
I opened the command prompt "run as administrator" to run these commands.
Everything I try fails. I have connected to a completely different network to eliminate that as the problem and that didn't fix anything. I have uninstalled and reinstalled node.js and that hasn't fixed the problem either.
I can ping registry.npmjs.org just fine.
What is causing this error?
I finally found the answer! I ran the following command in the command window:
echo %temp%
It had 3 temp paths in there. I removed the two I didn't need and voila, it works!

Can't install Semantic-UI via NPM

I've been trying to install Semantic via NPM for a while now and am having problems. I run npm install semantic-ui and it goes through the setup process. However, it stops at Finished 'install' after 3.61 s and never exits the process. If I manually cancel the process and navigate to the semantic folder and run gulp build I'm told there's no local gulp found. So I run npm install gulp just for fun. It installs and I run gulp build again but all of the gulp dependencies are missing.
Any ideas? It's getting frustrating because I've been tinkering with it for a few hours instead of getting to work on the actual project. Running npm install in the semantic directory or my project directory doesn't work either. Thanks for the help!
EDIT: I tried creating a new Ubuntu VM and installing Semantic the same way I was on my Mac. It worked with no problems leading me to believe it's something to do with my configuration on my Mac.
This is really odd, but after I got to the Finished 'install' step, nothing was happening. Just a solid cursor when the node deps should've been installing. I decided to hit return just to see if anything would happen and that seems to have done it. Hitting return gives me the spinning cursor and the deps install. I can successfully run gulp build after that. Weird.