npm errors and warnings in terminal - node.js

can anybody tells me what are those errors about and how to fix them?
Everytime i try to install something in node with npm these errors show up in terminalenter image description here

ENOENT stands for basically "Error, No Entry". this means it was looking for the package.json file and it couldn't find it.The fields mentioned below are also not found because they are a part of the package.json file
so create a package.json file in the current current directory using
npm init
and add the required content in the required fields
i would also recommend you to install the modules locally into the directory of the particular project using
npm install express --save
Hope my answer helps,
cheers

The error you are facing is because you do not have package.json file. Npm installs the package in a node_modules/ subfolder, but warns you that there is no package.json file. If you want to manage localy installed npm packages you should create a package.json file. Start by creating an empty folder:
$ mkdir myapp
$ cd myapp
and then create a new package.json executing
$ npm init
Answer (or skip) all questions and at the end a brand new package.json will be created.
You can get more information from the Getting started articles in npm documentation: Working with package.json

Related

Why is Heroku telling me it cannot find a package.json in my module when I do a heroku push

I created my own npm package from a fork of react-coverflow. It appears to be working fine in my app locally using it this way: "npm install react-coverflow-mod" --save.
I can run my app using "run with debug (F5)" in VsCode and npm start on the client folder to start the React front end.
Then I do an npm run build on the client folder, and it works just fine.
When I do a heroku push it fails everytime with this error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../react-coverflow-mod"
as it does not contain a package.json file.
1. I know there is a package.json in the module because I can install it via "npm install react-coverflow-mod": https://www.npmjs.com/package/react-coverflow-mod
2. The installed module has a package.json file in it
3. My github repo has a package.json in it: https://github.com/leroyvaughan/react-coverflow
I'm not sure how I can fix this. Do I need a package.json to go into the /Dist folder? What is wrong here with Heroku.
It seams like heroku try to install a package from a relative path instead of the published name. That would perfectly explain why you can run locally but not on a production environment.
Open your project and search for the exact string displayed in your log: "../../react-coverflow-mod" and you should be able to find quickly where it is.
If you run on a unix system (don't know about windows) you can do a search using grep:
grep -rnw '/path/to/somewhere/' -e '../../react-coverflow-mod'
Make sure it includes your root folder which contain package.json, and might we wise to ignore node_modules which is always massive.

NPM Install ENOENT no such file or directory

I'm getting this error when running npm install --save-dev gulp-coffee
ENOENT: No such file or directory
I have a package.json file in my root directory though
Didn't have any issues yesterday installing node modules but today I can't install dependencies
nothing seemed to work from other similar problems on stackoverflow, I ended up just deleting my repo. Then:
git clone [my github url repo]
cd [folder with node dependencies]
npm install (installs node packages based on root package.json file)
Run my gulp commands to test gulp watch, modified files being watched to see if gulp was working as intended. check to see files being changed as intended via git diff
Worked fine for me, it doesn't solve the original problem. Not sure why my package.json files were missing or why I could not repopulate them with a npm init

Install NodeJS package locally

When i try to install package on my local directory using npm install connect,but it just keep pop up some warning about
no such file or directory, open '/Users/felixfong/package.json'
But i don't not want to install package at my computer directory,i want to install at my local web app directory
Are you sure you are inside your local web app directory when you run the npm install connect command?
cd app-directory/
npm install connect
Also ensure that a package.json file is also present in the app-directory.
If it isn't present, you can use npm init command to create the package.json file interactively.
You have to go inside your project directory using
Then you can check package.json.
If package.json file is not there then initialize npm using the following command:
npm init
Then your can install the package using the following command:
npm install connect
'npm install connect' does not save the connect npm package in package.json file.
For saving the package into package.json file you have to givt --save option like:
npm install connect --save
Make sure that you are in web app's directory. Current path can be checked via command pwd in Linux and cd in windows. Navigate to your web app directory if you are somewhere else. Check existence of package.json by listing the content of the folder. ls and dir can be used for ubuntu and windows respectively for listing content. Commands for ubuntu are as below:
pwd
cd your-path/
ls
Now Initialize npm in your web app directory if package.json is not already existing there.
npm init
This will ask some information like:
name of the app,
its version,
description,
entry point,
test command,
git repo,
keywords,
author and
license (if any)
You can select default values by leaving the fields empty if you aren't sure or confused about any field. Combining this information as json, npm will create a file named package.json
Just run the desired command now after initialization of npm or if its already initialized:
npm install connect

npm install resulting in 'ENOENT: no such file or directory'

I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\Users\username\Desktop\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:
ENOENT: no such file or direcotry, open 'C:\Users\username\package.json
I'm attempting this from a clean install and cmd is running as admin.
Any ideas?
I was facing the same issue. I firstly delete my node_modules and delete the cache by following command:
rm -rf node_modules && npm cache clean --force
then I delete the package-lock.json file from my project and then hit npm install in command prompt and it works.
As already pointed out by Subburaj this is because you are missing a package.json.
Just run npm init to initialize that file for you; afterwards it should work.
If you are working on a Windows machine using Vagrant/VM, there's a chance that symlinks are the culprit for your problem. To determine if that is the case, simply copy your package.json and package-lock.json into a test directory that is not mounted/shared between OSs.
mkdir /tmp/symlinktest
cd {{your directory with your package*.json}}
cp package*.json /tmp/symlinktest
cd /tmp/symlinktest
npm install
If this results in a successful install, you'll need to either exclude the node_modules directory from the mount (there's various articles on doing this, however I can't say I've had success) or run npm install outside the mounted volume.
I deleted the package-lock.json and It worked for me.
Basically I was Offline while I tried to install with npm, so go online and try
npm install again
Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.

Running "npm install --save X" in folder without package.json file

I am writing a library and need to know what will happen if a user tries to run npm install -S X in their project before a package.json file exists.
I just tried this on Windows, and sure enough, NPM did not barf and went along with it's business but when the install command completed, there was still no node_modules folder nor a package.json file.
Does anyone know what is expected to happen? I assume I should require the users of my library to run "npm init" before running "npm install X" ?
Looks NPM does throw an error at the end of the install -
ENOENT: no such file or directory, open 'package.json'
but I wonder if that prevents the install process from create a node_modules dir, and actually putting the dependency in there.
npm install without the -g flag will walk up the folder tree checking for folders that contain either a package.json or a node_modules folder.
If either of those conditions are met, then that folder will be treated as the current directory for the purpose of the npm commands you are running. If no such folder is found, then the current folder is used.
As you noted, a node_modules folder will be created and after the package is loaded into the cache it will be unpacked into that folder.

Resources