I am new to ReactJS, I was following one of the tutorials in "TutorialsPoint".
In Step 2: After the folder is created we need to open it and create empty package.json file inside by running npm init from the command prompt and follow the instructions.
C:\Users\username\Desktop\reactApp>npm init
By running the above command I am unable to create and package.json Only this thing is coming up after running init.
In Step 4: it asks to add dependencies and plugins
In Step 5: it asks to open the package.json and delete "test": "echo \"Error: no test specified\" && exit 1"
inside "scripts"
object.
Now how can I open package.json, if I was not been created from the beginning?
The easiest way to create a package. json file is to run npm init to generate one for you. It will ask you to fill out some fields, and then create a package. json file in the current directory.
This is because it overwrites the existing package. json file or the file path is not correct. Also Admin permission is not granted to create such file. so try VS Code or IDE you all use to run as Administrator.
The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.
Use npm init to generate package. json files for you! Per npm init : Use npm install <pkg> --save afterwards to install a package and save it as a dependency in the package. json file.
The command npm init
"will ask you a bunch of questions, and then write a package.json for you."
The first prompt, as shown in your screen capture, asks you to enter a package name. You can just hit Enter to skip through the prompts and accept the default values if you are unsure of what information to provide.
You can also use -y
/--yes
to skip the questionnaire altogether. For example, npm init -y
. (Note: -f
/--force
also work.)
Each prompt corresponds to a field in the package.json file. Consequently, you can construct this file yourself or copy and modify an existing one from another project.
A package.json must have:
There are two ways to create a empty package.json file:
Run a CLI questionnaire to create a package.json with values that you supply. For that run the command:
npm init
Create a default package.json. For that you just need to run the same command but with the --yes or -y flag.
npm init --yes
and it will create the package.json file in the dir where you run the command and will display the code shown bellow:
{ "name": "reactApp", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With