Reputation: 1435
I installed create-react-app package locally. But it did not work. When I installed it globally using -g
, it worked.
I have came across several other packages which some of them works when installed globally but not locally and vice versa.
How someone know a particular package to install globally or locally?
Upvotes: 1
Views: 75
Reputation: 10604
Use npx create-react-app
, this will download the React Cli
and after creating the project it will delete the Cli
from your local system.
npm will fist scan the local node_module folder in the project if it find the package then it will use it, otherwise it will go up to the tree and search in the the global package.
All project dependency can be used globally or locally in project.
But in this case create-react-app
is used as a shell tool not as a project dependency so it has to be in PATH environment variable.
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
Try this, hope this will solve the issue.
Upvotes: 1
Reputation: 61
I dont think this should happen. You can follow this document to know about global vs local setup:
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
What does it means? That if you want to execute a package without installing it on your computer and then launch it you can use npx directly. for e.g;
- create-react-app is an utility to bootstrap a react project.
- if you use it with npx ( npx create-react-app my-app ) you will have your my-app project in place without the need to install create-react-app itself.
- npm install create-react-app and then create-react-app my-app if you use npm
Upvotes: 1