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: .
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.
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.
Share Improve this question edited Oct 29, 2018 at 11:11 R. Richards 25.2k10 gold badges66 silver badges65 bronze badges asked Oct 29, 2018 at 10:45 anhtv13anhtv13 1,8085 gold badges35 silver badges55 bronze badges 8- "Because it's just a command, so please don't send me a link, please just paste the command here." Well, the command is in the link that you posted. – str Commented Oct 29, 2018 at 10:46
- @str I did try the command but it doesn't work for me :( – anhtv13 Commented Oct 29, 2018 at 10:47
- 2 The readme explicitly says 'the scripts are bash scripts and may not run on Windows machines. If that is the case, please use Git Bash'. Judging by your command prompt, you're using PowerShell. – Joe Clay Commented Oct 29, 2018 at 10:52
- 1 @anhtv13: Yes - the scripts contained in the package are written in Bash, not JavaScript. You must be using a Bash prompt like Git Bash or Cygwin to run them. – Joe Clay Commented Oct 30, 2018 at 9:08
- 1 @JoeClay thank you very much. I created a new component successfully using Git Bash. Since you didn't post an answer, I cannot vote your suggestion as marked answer but anyway, thank you so much. – anhtv13 Commented Oct 30, 2018 at 9:16
4 Answers
Reset to default 4With 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
Check out the react-component template from my new library templates.
Supports: typescript, testing library, storybook, multiple css languages, automatic formatting, and more!
Feedback or contributions are welcome!