可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to install the dependencies of some example Express apps 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
Does anyone know what might be the root of this problem?
I'm running:
- Windows 7 64 bit
- npm 1.1.1
- node 6.11
- express 2.5.8
回答1:
Update 2018
This is becoming quite a popular question and my answer (although marked as correct) is no longer valid. Please refer to Deepali's answer below:
npm init
Original Outdated Answer
I think you forgot to setup the directory for express:
express <yourdirectory>
Once you do that you should be able to see a bunch of files, you should then run the command:
npm install -d
Regards.
回答2:
I think, npm init
will create your missing package.json
file. It works for me for the same case.
回答3:
I'll be brief but deadly. :) install -d will not work for you. It's simple. Try
$ npm install -g express
回答4:
Follwing the below steps you well get package.json file.
npm --version
npm install express
npm init -y
Link : http://www.codingslover.com/2017/02/npm-node-js-cant-find-packagejson.html
回答5:
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
回答6:
Use the command in win7/win8/win10 (CD) for moving folders:
Enter your projects folder
Run: npm install -d
回答7:
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
回答8:
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
回答9:
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
回答10:
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
.
回答11:
ok, try to go to the home "user@user:~$ " (cd + enter key), and npm install -g your your_module.
回答12:
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).
回答13:
Beginners usually try use command on random localization.
after downloading or creating project you have to go into this project. Inside is file package.json
cd <path_to_project>
npm install
回答14:
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.
回答15:
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.
回答16:
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
回答17:
I have run npm install -y
to skip the question step for creating the missing file package.json
, y
means yes
回答18:
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.
回答19:
just install any package you want with -g
npm install -g express
回答20:
Adding -g before the package name worked for me. Looking for documentation to explain why this works..
回答21:
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/