npm can't find package.json - node.js

I'm trying to install the dependencies of some example: npm's express 2.5.8 that I've downloaded, but all of the apps throw the same error:
c:\node\stylus>npm install -d
npm info it worked if it ends with ok
npm info using npm#1.1.1
npm info using node#v0.6.11
npm ERR! Couldn't read dependencies.
npm ERR! Error: ENOENT, no such file or directory 'c:\node\stylus\package.json'
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-d"
npm ERR! cwd c:\node\stylus
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! path c:\node\stylus\package.json
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory 'c:\node\stylus\package.json'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\node\stylus\npm-debug.log
npm not ok
The blockage appears to be:
no such file or directory 'c:\node\stylus\package.json
Did I miss a step that creates the package.json ?
I'm running:
Windows 7 64 bit
npm 1.1.1
node 6.11
express 2.5.8

I think, npm init will create your missing package.json file. It works for me for the same case.

In your project's folder, you need to initialize the package.json file by running the following in the terminal:
npm init
After that, you should be able to install any packages as you would expect, like express:
npm install express
Shout out to Deepali's answer.

I'll be brief but deadly. :) install -d will not work for you. It's simple. Try
$ npm install -g express

Follwing the below steps you well get package.json file.
npm --version
npm install express
npm init -y

If Googling "no such file or directory package.json" sent you here, then you might be using a very old version of Node.js
The following page has good instructions of how to easily install the latest stable on many Operating systems and distros:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Beginners usually try the npm command from random locations.
After downloading or creating a project, you have to cd into this project folder. Inside is the file package.json.
cd <path_to_project>
npm install

Use the command in win7/win8/win10 (CD) for moving folders:
Enter your projects folder
Run: npm install -d

try re-install Node.js
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
and update npm
curl -L https://npmjs.com/install.sh | sudo sh

Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
sudo npm install npm -g
Test:
npm -v //The version should be higher than 2.1.8
After this you should be able to run:
npm install

It may be very evident,
but try to launch CMD (for Windows) from the project folder,
where your package.json file is located.
Do not launch CMD from System or from "Search bar" in Win or
move to your project folder with help of cd command and then launch npm start.

I had a similar problem with npm. The problem was that I had the project inside two folders of the same name. I resolved it by renaming one of the folders to something else (outer folder recommended).

It by itself says that package.json is not available in your project.
So, to create package.json, use the following steps:
open command prompt on your project directory
npm init (it will ask you to enter lots of entries like name, version, desc, etc., enter some random values and click enter).
type yes and click enter
Now try again.

Go inside the project folder and check whether the package.json file does exist.
If you are creating the project using Visual Studio Angular project, make sure you run this command inside the ClientApp Folder. there is a good chance, you could be looking for project.json file outside the ClientApp folder.

if the package.json file in the project directory is missing then you can create it by
npm init.
if the package.json file is already created in the project directory then there is a possibility that you are not running your project from the right path.
Use cd your-project-path in the terminal and then run your project from there.

npm init -y
use this command, it will automatically create package.json file with all your machine information.

I found myself here trying to resolve the same error message:
npm ERR! message ENOENT, no such file or directory 'c:\<some_folder>\package.json'
The error could be due to two reasons:
You do not have the package.json
You have the package.json, but you are running npm start in the wrong folder
To troubleshoot the first cause, you need to create a package.json using:
npm init
To fix the second cause, make sure the folder you are running the npm start command is the same folder as the package.json

I was experiencing this identical error and terminal (foolishly, on my part) was in a parent directory instead of the correct one (where package.json was correctly located).
All I did in terminal was cd [insert correct directory name here, overwriting brackets] and that corrected the problem.

My issue was I didn't have a package.json file for some reason. After I wget this file into my directory, I was able to run npm install
https://raw.githubusercontent.com/twbs/bootstrap/master/package.json

Thank you!
I also tried many options for this. I am also using windows.This command helped and saved my time:
npm install -g npm#lts

ok, try to go to the home "user#user:~$ " (cd + enter key), and npm install -g your your_module.

just install any package you want with -g
npm install -g express

For the following command
sudo npm install react browserify watchify babelify --save-dev
I got same error
saveError ENOENT: no such file or directory, open
'/Users/Path/package.json'
But when I run the command
sudo npm install -gd react browserify watchify babelify --save-dev
then no missing file or directory message appeared.

I have run npm install -y to skip the question step for creating the missing file package.json, y means yes

I was also facing same issue while installing typescript. I just initialized an package.josn file by the following command
npm init -y
And then i installed my typescript
npm install -g -typescript
http://blossomprogramming.blogspot.com/

Please check the directory or the folder in which you're installing your new package.
This happened to me as well,
My whole project was in a subdirectory and I was trying to install in the main directory. After checking the whole thing I found out that I had to install in the subdirectory where my project files and package.json files are located and it's done.
Hope this helps...

the previous tips do not pay attention to any change for me. at the end this works for me:
delete the local repo folder
git clone https ... myRebo.git
npm install
npm start
hope it helps somebody

I got this error because I was trying:
npm install --save-exact express#4.17.1 cors#2.8.5 express-bearer-token#2.4.0
#okta/jwt-verifier#1.0.0 mongoose#5.6.7
which I got from: https://developer.okta.com/blog/2019/09/11/angular-mongodb
I had to separate the packages and run them one by one. I think the backslash caused problem.

Adding -g before the package name worked for me. Looking for documentation to explain why this works..

Generate package.json without having it ask any questions. I ran the below comment in Mac and Windows under the directory that I would like to create package.json and it works
$ npm init -y
Wrote to C:\workspace\package.json:
{
"name": "workspace",
"version": "1.0.0",
"description": "",
"main": "builder.js",
"dependencies": {
"jasmine-spec-reporter": "^4.2.1",
"selenium-webdriver": "^4.0.0-alpha.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

Related

npm ERR! must provide string spec

I'm having this error since a while, in this case, the problem occur executing the following command.
npx create-react-app my-app
Actually, it happens with any npm commands as well, I tried deleting package.json, changing npm versions and yet didn't work, so I'm here asking for help.
This is the entire error:
C:\Users\c>npm install
npm ERR! must provide string spec
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\c\AppData\Local\npm-cache\_logs\2022-01-28T16_50_23_009Z-debug.log
Version of npm and node:
node --version
v16.13.2
npm --version
8.3.2
I had the same issue, it was a missing version in my package.json
look like mistakenly I removed some text
"dependencies":{
"angular/cli" :"{}"
}
try to update your npm: npm upgrade
then: npm clean cache
Following, i'm in the exact same position. Tried changing the NodeJS version using NVM and now some of the commands work (npm -v shows im running 8.1.0) but npm update and npm/npx create-react-app give me an " ERR! must provide string spec " !
I faced this same issue yesterday.
This is what I did to resolve it:
Uninstalling node entirely and removing node_modules and package.lock.json from the project directory.
Install node afresh and run npm install in your project directory.
I tried to reactivate an old project which had packages noted down differently then usual in package.json. They had an id and locator parameter, like:
"ImagePicker": {
"id": "ImagePicker",
"locator": "https://github.com/dhavalsoni2001/ImagePicker.git"
}
After removing / replacing them by version numbes, i could install.

Laravel Compilation "Error: Cannot Find PATH/node_modules/laravel-mix/.."

When I run commands like:
npm run dev
npm run watch
to compile my project. I receive an error that says the laravel-mix directory does not exist.
Error: Cannot find module 'PATH/node_modules/laravel-mix/setup/webpack.config.js'
I have deleted the node_modules directory and used npm install to attempt to get it to install properly and it still is not there. "Laravel-mix" is in the package.json file as a dependency, so to my knowledge running npm install or npm install laravel-mix should do the trick, but it isn't working. Any information about this would be greatly appreciated.
npm -v 6.14.1
node -v 12.16.2
Have you already run the following?
npm install laravel-mix
npm install cross-env

Can anyone explain this error when I run "npm run ng new app"?

So I'm trying to make a new angular app for the first time, and I installed it using npm i -g #angular/cli. When I try to make a new app using npm run ng new app, it gives me this error:
npm ERR! path E:\ddii\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'E:\ddii\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users...\AppData\Roaming\npm-cache_logs\2018-09-10T20_22_50_118Z-debug.log
In short, you are running the command incorrectly. Remove the npm run from the front of your command, and it should work.
When you say npm run blah, npm does a lookup in your package.json for a script called blah or in your case ng. So... if you are running npm run ng new app, npm wants there to be a package.json in your current directory, and in that package.json, npm expect a script called ng. So if you don't have a package.json in your current dir, then you are going to get an error.
Instead, close your terminal, and open a new terminal and run simply ng new app.
I struggled to find this answer myself, as the other answers on this question do not address the real underlying issue.
All the other answers suggest to install ng GLOBALLY using (npm i -g ...), with the side effect that a symlink to ng will be on your PATH.
Based on OP's question, I do concede he was most likely attempting to scaffold a new Angular app from the GLOBALLY installed ng. So this handles 90% of people's questions, and is all fine and nice.
I, however, want to use the LOCALLY INSTALLED ng, which is why I have an npm-script in my package.json for it:
{
...
"scripts": {
...
"ng": "ng",
...
}
If this describes your use case like it does mine, then read on.
npm run ng update succeeds for me, whereas other more complex commands with more arguments—including command-line switches—fail outright (npm run ng -- update #angular/cli --migrate-only tslint-version-6).
The answer lies in that you must delimit the start of arguments being passed to npm run-script with -- (see https://stackoverflow.com/a/14404223/1438576):
npm run ng -- update #angular/cli --migrate-only tslint-version-6
So in OP's case, assuming he already had a locally-installed copy of ng with a package.json (which I admit is doubtful), he could have done:
npm run ng -- new app
Anyway, hope this helps others.
If you want to run it without the npm run ..., you need to install ng globally, I would do npm install -g #angular/cli, however I'm running linux, for windows I've found this thread ng is not recognized as an internal or external command
It should help you install a global version of angular-cli, you'll basically do two things:
Install globally angular-cli (if you don't have it).
Make sure it's in your environment variable's PATH.
Check the question answers, details are there.
Could help for future references
At least for me this work.
Sometimes, the reference to the file ng.cmd (in case of Win users) is not well formed and you have to call it and pass the arguments directly
e.g.
< path-where-ng.cmd-file-is-located >\ng.cmd new app
Running calling ng.cmd file directly
It says: ' "ng" is not recognized as an internal or external command, operable program or batch file.'
And it works even if you do not have admin permissions for any reason

How to Reinstall Broken npm

I just installed node v9.11.1 when I try to use npm I keep getting the following error:
npm WARN npm npm does not support Node.js v9.11.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
I tried to do npm i -g npm but it couldn't update itself, it just kept throwing the same error above.
When I run npm -v it says 5.5.1 it seems the latest version is currently 5.8.0.
I tried deleting the folder and running the repair function on the node.js installer, but it didn't replace the module.
Delete the Global NPM Folder
https://stackoverflow.com/a/5926706/349659
npm list -g
For Windows this will most likely be:
%AppData%\npm\node_modules
You can paste that into a folder's address bar and it will take you there.
Once there delete the folder named npm.
Download the Latest Release of NPM
https://github.com/npm/cli/releases/latest
Grab the zip and unzip it to your node_modules folder that you just deleted the npm folder from.
Rename the folder you extracted from the zip to npm
If you get any warnings about the file path or name being too long skip the warnings.
Update for Good Luck
Now you should be able to run npm i -g npm to update/reinstall npm without any warnings.
I find this step especially important if you had errors in Windows about the path or file name being too long.
You may get the following errors. If you do go and delete or move the files it has listed and you should be able to run npm i -g npm successfully.
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Move it away, and try again.
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.
Somehow I had a broken installation of npm so reinstalling it with itself (e.g. npm install -g npm or similar) would not work.
The npm readme actually defines a very simple way to install npm again using this curl command:
curl -qL https://www.npmjs.com/install.sh | sudo sh
This installation script actually removes any existing npm installations, then installs the latest version for you.
Try this:
npm install npm#latest -g
More info here.
Try this command to reinstall npm
npm install -g npm-reinstall
If you are using a linux distribution add sudo
sudo npm install -g npm-reinstall
Since I am all about one-liners, let me make this very damn easy for you.
Open your GitBash or Cygwin(I think both GitBash and Cygwin stores the Windows pre-defined Environment Variables and paths in their storage, so this becomes way easy), on any path, and run this one-liner from there:
rm -rf $APPDATA/npm; npm install -g npm#latest; npm list -g;
rm -rf $APPDATA/npm; - this will purge the old global npm folder completely.
npm install -g npm#latest; - this will install the latest version of NPM available(so no need to install minor versions after this ;)).
npm list -g; - this will show you details of your NPM global profile.
If anyone insists on doing this in PowerShell then here's the way:
$env:Path += ";C:\Program Files\nodejs\"
cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; npm install -g npm#latest; npm list -g;
$env:Path += ";C:\Program Files\nodejs\" - Ensures that Nodejs is added to Path for atleast running PowerShell session. (Caution: Run this only once, as long as no errors.).
cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; - Ensures that the necessary step of fully purging the %APPDATA%\npm folder is done with measure.
For me even deleting npm folder or reinstalling Node didn't help. After updating Nodejs and npm to latest version (Node 10.19, npm 6.14.3) of my CentOS 6, I've got constant libs error with npm while Node was fine.
What's worked - n Node version manager. With this command I could reverse my npm version: n -p 6.13 link

create-react-app, installation error ("command not found")

I have installed create-react-app exactly as instructed on the facebook instruction page (https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html):
First, install the global package:
npm install -g create-react-app
I did this. It appeared to work fine - the file was installed to
users/*name*/.node_modules_global/lib/node_modules/create-react-app
I'm not really sure why global install takes it to this path, but there you have it.
Next instruction:
Now you can use it to create a new app:
create-react-app hello-world
Couldn't be simpler, right? But Terminal spits out this at me:
-bash: create-react-app: command not found
It's probably something very simple I'm missing but I don't really know where to look. If anyone can help I'd really appreciate it!
Note: I'm using Node v6.3.1, and npm v3.10.3
You are able to apply the following solution:
$ npm config set prefix /usr/local
$ sudo npm install -g create-react-app
$ create-react-app my-app
The environment variables are not set properly.
When you run the create-react-app it shows you a path along with the error. Copy that path and add it in the environment variable.
Alternatively you can use the command:
npx create-react-app <app_name>.
This will do the work for you.
Your Node setup looks incorrect. It's not an issue with Create React App—it seems like you can't run any global Node commands.
It looks like ~/.node_modules_global/bin is not in your PATH environment variable so it can't execute global commands. That's just how Bash works—it can't guess where the command lies, you need to tell it. I would assume Node installation should do this by default but it depends on how you installed Node.
So make sure that directory is in your PATH and try again. If you use Bash, add this to your .profile and then restart the Terminal:
export PATH=$HOME/.node_modules_global/bin:$PATH
Try this. It worked or me. I found this in the React documentation. "Npx" is not a typo. It's a package runner tool that comes with npm 5.2+.
npx create-react-app my-app
In 2020 Dec 17
Install Nodejs & npm
sudo apt update
sudo apt install nodejs
sudo apt install npm
if you install maybe show you this like errors for Reactjs setup.this helpful for you
npm install -g create-react-app
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/create-react-app'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2020-12-17T14_16_02_442Z-debug.log
then When you type after this
create-react-app test-react-app
Show you in terminal
zsh: command not found: create-react-app
you fix this error by using this command
sudo npm install -g create-react-app
create-react-app test-react-app
I hope work fine for you also.
Use npx instead of npm.
Check this out-> https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
Answers given above are right but I want to share some things that I also faced and these are basics.
To setup react project
If you want to create a node environment
$ sudo apt-get update
$ sudo apt-get install nodejs
(Sometimes we can also run without sudo; but sudo means install in system level.)
$ sudo apt-get install nodeenv
$ nodeenv env
$ source /bin/activate
If you want to create new react app then
$ npm install create-react-app
If an error occurs create-react-app: command not found then install with -g, it happens because node is installed globally and it is not getting the node in local
$ npm install -g create-react-app
$ create-react-app app_name
$ cd app_name
app_name$ npm start
I hope you already installed Node package manager(npm).
now run npm install -g create-react-app, if everything fine then you can use create-ract-app command.
if you are getting any permission error just sudo npm install -g create-react-app.
I hope it will work.
Happy Hacking.
if you face following this problem:
create-react-app: command not found
solution:
sudo npx create-react-app react_spa
cd react_spa
sudo npm start
I hope its work.
If above answers are not working, then try this
update the npm version (npm install npm#latest -g)
clear the cache (npm cache clean --force)
create the react project (npx create-react-app myapp)
(while running the 3rd command, make sure that create-react-app is already installed in the pc)
This is how I get it fixed.
Step # 1:- Make sure, Node js and React js is installed globally. You can check Nodejs by
node --version . If not installed, install and run
export PATH=$HOME/.node_modules_global/bin:$PATH
Step # 2:- Clean your npm cache by following the command
npm cache clean --force
run
sudo npx create-react-app your-app-name
And that's it. you're done.
Please note, This solution worked for me for MAC OS
I tried all methods listed above and in other sites. They weren't working for me. But for some reason I decided to add the create-react-app directory into my system variables as a last ditch method and to my surprise this actually worked.
I faced a similar challenge but on running the command
npm i tar
I was able to resolve the issue.

Resources