React: npm command to create a new component? - javascript

I'm new to React and I want to create a new component by a command.
The command which I want to create will be the same output of the command in Angular 2: "ng generate component Test".
I have search on the internet and there is a reference: https://www.npmjs.com/package/create-reactjs-component.
However, it doesn't work for me. The terminal shows errors:
PS C:\Users\anhtranv1\Desktop\react-app> npm install -g create-reactjs-component Test
npm ERR! code E404
npm ERR! 404 Not Found: Test#latest
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\anhtranv1\AppData\Roaming\npm-cache\_logs\2018-10-
29T10_39_16_863Z-debug.log
Is there anyone can give me a command to create a component in react?
Thank you in advanced.

With npm install -g create-reactjs-component you install the npm package globally.
After you installed the package globally with the above command you can create a component with create-reactjs-component YourComponentName.
Please read the documentation of the package, it's all described there.

You might want to check out generate-react-cli. Really straightforward and easy to use.
install: npm install -g generate-react-cli
run: generate-react component Box
That's it
repo: https://github.com/arminbro/generate-react-cli

What are you telling him here :
npm install -g create-reactjs-component Test
Is to install Globally create-reactjs-component AND Test, however there is no Test defined in npm repository,
Install your CLI tool dep
Create your component

Related

MapBox SDK for React Native Installation shows Error

I created a React Native project with Expo using expo init MapTry. I am currently trying to install MapBox library into it. For some reason I get an error at the first step after trying to install it. I followed this guide of installation: https://github.com/rnmapbox/maps#Installation but for some reason I am getting an error message when I try to run npm install rnmapbox/maps#main --save from the terminal. The error says the following:
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
I also tried to search for it in the official NPM site and found this one: https://www.npmjs.com/package/#rnmapbox/maps . After running the following code: npm i #rnmapbox/maps which was written there, I get the same error message as written above. What should I do? How can I use MapBox library in React Native?
try to run this command in your terminal
with NPM
npm install #rnmapbox/maps --save
with YARN
yarn add #rnmapbox/maps

npm doesn't work for me because of wrong config

When I want to use the npm package manager for js we package or project like this command:
npm start
It shows me :
npm ERR! code E418
npm ERR! 418 Unknown - GET https://repo.huaweicloud.com/repository/npm/yarn
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Amir\AppData\Local\npm-cache\_logs\2021-12-08T13_04_36_000Z-debug.log
I think my npm mirror is wrong, how can I fix it?
You can use
npm config --global edit
and
npm config edit, it will open the npm config with your default editor.
and then remove the registry line for each file to reset it to defaults.

react-native:Unable to import react-native after installing through npm

I am in my initial stages of learning react and have a limited understanding of npm manager and importing libraries into project.
For my current project, I had installed react-native using
npm install react-native
This also reflects in my package.json and node_modules folder
"react-native": "^0.61.5"
Now, when I try to import react-native as follows into AppCarousel.js
import React from 'react';
import {Dimensions} from 'react-native';
and then build the application , i get the following error message
.\src\Components\AppCarousel.js
Cannot find module: 'react-native'. Make sure this package is installed.
You can install this package by running: npm install react-native.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react#1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\{USER}\AppData\Roaming\npm-cache\_logs\2020-01-09T13_08_54_364Z-debug.log
The terminal process terminated with exit code: 1
I tried referring to the the following questions i) link1 ii)link2
I cannot make out if this is a bug in npm or if there is a lack of understanding for installing packages on my side. Any help will be appreciated, thanks.
Terminal to kill the process:
ps -ax | grep npm
Then try to navigate to your directory in your terminal and try to do write this:
npm I react
or again:
npm i react-native
Simple explanation to get in use with TypeScript and React:
https://facebook.github.io/react-native/docs/typescript

npm ERR! request to https://registry.npmjs.org/node-modules failed, reason: error:0906D06C:PEM routines:PEM_read_bio:no start line

I am getting this error while installing any JS package , I have done lots of search but no luck. So please let me know where i am making mistake.
npm ERR! request to https://registry.npmjs.org/node-modules failed,
reason: error:0906D06C:PEM routines:PEM_read_bio:no start line
WebServer : Apache2(xampp)
Node : v9.3.0
NPM : 5.5.1
I think that first you need to start prompt as an administrator, then run npm cache clean -f then try to run npm install, by this command the npm will install the packages listed in package.json.
Or
You can run npm config set registry http://registry.npmjs.org/ so you can run npm install -g node-modules. Read more in this answer.
I faced the same problem and finally I was able to solve the exact above error by doing the following steps:-
check version of your npm with npm -v
run npm -g install npm#<version> This step is important as npm is getting installed globally here.
Now run the command where you want to install something globally using npm. In my Case the command was npm install -g #angular/cli#6.2.9 which worked fine after these changes
If you are still facing the problem, I would recommend to follow the instructions about installing nodejs perfectly from here https://docs.npmjs.com/try-the-latest-stable-version-of-npm#upgrading-on-windows

npm install couldnt install angularjs libraries

I have installed mean.io and ran sudo npm install. Actually following commands in sequence
sudo npm install -g meanio
mean init yourNewApp
cd yourNewApp
sudo npm install -g bower
sudo npm install
It is supposed to download and install angularjs libraries into public/system/lib. After doing the above steps public /system/lib is not created due to which when I start the application I get the error
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, open '/home/santhosh/dev/scaleqa/mean_tut/old mean/temp/myapp/public/system/lib/bootstrap/dist/css/bootstrap.css'
[nodemon] app crashed - waiting for file changes before starting...
Is it something to do with certain npm/angularjs server being down. I have faced this problem earlier also but got fixed on 2nd try and I didn't bother to do more research. This became a big issue when I try to pull my repo into cloud and start the application. public/system/lib is added in .gitignore by default and is expected to be created during npm install.
I get following warnings with sudo npm install
npm WARN package.json mean-connect-mongo#0.4.3 No repository field.
npm WARN cannot run in wd mean#0.3.3 node node_modules/bower/bin/bower install (wd=/home/santhosh/dev/scaleqa/mean_tut/old mean/temp/myapp)
this is link to package.json
The problem maybe related to running npm install as sudo, which can cause problems. As mentioned in another stack overflow question, this can be worked around in a couple ways. But because it looks like this is being run from your home directory, you really shouldn't need to run npm install as root.
Try to issue the same commands, but the last without sudo:
sudo npm install -g meanio
mean init yourNewApp
cd yourNewApp
sudo npm install -g bower
npm install
Note that the reason you may need to run npm install -g <package> using sudo is because by default npm uses /usr/local for global installs, which can be a restricted directory. However, when you install a package locally (without the -g flag) you should not need to run as root.

Categories

Resources