Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm init doesn't create package.json

Tags:

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.

enter image description here

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?

like image 448
SumitHusky Avatar asked Jun 17 '16 18:06

SumitHusky


People also ask

Does npm init create package json?

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.

Why package json is not created?

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.

Why npm init is not working?

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.

How npm create package json?

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.


2 Answers

Complete the npm init prompts

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.

like image 173
gfullam Avatar answered Oct 14 '22 05:10

gfullam


A package.json must have:

  • A name all lowercase one word, no spaces, dashes and underscores allowed;
  • A version in the form of x.x.x;

There are two ways to create a empty package.json file:

  1. Run a CLI questionnaire to create a package.json with values that you supply. For that run the command:

    npm init

  2. 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" } 
like image 22
AnoopDixit Avatar answered Oct 14 '22 06:10

AnoopDixit