node.js npm 找不到 package.json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9484829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:14:59  来源:igfitidea点击:

npm can't find package.json

node.jsexpressnpm

提问by imjp

I'm trying to install the dependencies of some example: npm's express 2.5.8that I've downloaded, but all of the apps throw the same error:

我正在尝试安装一些示例的依赖项:express 2.5.8我下载的npm ,但所有应用程序都抛出相同的错误:

c:\node\stylus>npm install -d
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
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!     <[email protected]>
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

没有这样的文件或目录 'c:\node\stylus\package.json

Did I miss a step that creates the package.json?

我是否错过了创建 的步骤package.json

I'm running:

我在跑:

  • Windows 7 64 bit
  • npm 1.1.1
  • node 6.11
  • express 2.5.8
  • 视窗 7 64 位
  • 1.1.1
  • 节点 6.11
  • 快递 2.5.8

采纳答案by Aldo

Update 2018

2018 年更新

This is becoming quite a popular question and my answer (although marked as correct) is no longer valid. Please refer to Deepali'sanswer below:

这正成为一个非常受欢迎的问题,我的回答(虽然标记为正确)不再有效。请参考以下Deepali 的回答:

npm init

Original Outdated Answer

原始过时的答案

I think you forgot to setup the directory for express:

我想你忘了为 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.

问候。

回答by Deepali Agarwal

I think, npm initwill create your missing package.jsonfile. It works for me for the same case.

我认为,npm init会创建您丢失的package.json文件。对于同样的情况,它对我有用。

回答by Zoe Marmara

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

我会简短但致命。:) install -d 对你不起作用。这很简单。尝试

$ npm install -g express

回答by Elangovan

Follwing the below steps you well get package.jsonfile.

按照以下步骤,您将获得package.json文件。

npm --version
npm install express
npm init -y

Link :http://www.codingslover.com/2017/02/npm-node-js-cant-find-packagejson.html

链接:http : //www.codingslover.com/2017/02/npm-node-js-cant-find-packagejson.html

回答by Gerry

If Googling "no such file or directory package.json"sent you here, then you might be using a very old version of Node.js

如果谷歌搜索“没有这样的文件或目录 package.json”将您发送到这里,那么您可能使用的是非常旧版本的 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

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

回答by Franklin CI

Use the command in win7/win8/win10 (CD) for moving folders:

使用win7/win8/win10(CD)中的命令移动文件夹:

  1. Enter your projects folder

  2. Run: npm install -d

  1. 输入您的项目文件夹

  2. 跑: npm install -d

回答by Victor1125

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.

初学者通常从随机位置尝试 npm 命令。下载或创建项目后,您必须 cd 到此项目文件夹中。里面是 package.json 文件。

cd <path_to_project>
npm install

回答by Cosimo de' Medici

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.

Node 安装了 npm,所以你应该有一个 npm 版本。但是,npm 比 Node 更新得更频繁,因此您需要确保它是最新版本。

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

回答by lrj

try re-install Node.js

尝试重新安装 Node.js

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

sudo apt-get install -y nodejs

sudo apt-get install -y nodejs

sudo apt-get install -y build-essential

and update npm

并更新 npm

curl -L https://npmjs.com/install.sh | sudo sh

回答by Yipeekiyay

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).

我对 npm 有类似的问题。问题是我有两个同名文件夹中的项目。我通过将其中一个文件夹重命名为其他文件夹(推荐外部文件夹)来解决它。