npm install没有创建node_modules文件夹

时间:2016-06-27 06:19:38

标签: javascript node.js npm

我只是想尝试运行npm install。在本地目录中,并不断收到这些错误:

{
  "name": "speech-recognition",
 "version": "1.0.0",
 "description": "speech recognition app",
 "main": "application.js",
 "scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "start": "node server.js"
 },
 "author": "Lisa Buch",
 "license": "ISC"
 }

我正在做的就是进入我的目录并运行npm install。我也有一个packages.json文件。知道为什么这不起作用??? 编辑:packages.json文件的内容如下:

    <div ng-app="demoAddList" ng-controller="myCtrl">
    <select ng-model="selectedProgram"  ng-options="programofinterest.id as programofinterest.text for programofinterest in programofinterests">
            </select>
        </div>
<p>Try to add the same item twice, and you will get an error message.</p>

8 个答案:

答案 0 :(得分:7)

请检查您当前的目录。它应该包含一个具有适当结构和依赖关系的package.json文件。

https://docs.npmjs.com/files/package.json

如果您没有package.json文件,则表示您从头开始创建项目。在这种情况下,您可以使用以下命令创建package.json文件。

npm init

并使用npm install命令安装软件包名称。例如如果你想安装快递包。使用以下命令

npm install express --save

这里--save选项会使用包及其版本更新package.json文件。

答案 1 :(得分:1)

使用npm install --save

尝试

答案 2 :(得分:1)

问题似乎是自我描述性的:

  

npm ERR! eisdir与npm无法找到相关   

中的package.json

这意味着npm install无法在文件夹中找到package.json文件

您可以在该文件夹上运行npm init。这将询问一系列项目设置问题,最后将创建一个package.json文件。

然后,您可以在该文件夹上运行npm install -save-dev以安装依赖项

答案 3 :(得分:0)

我通常不会犯此错误,但是根package.json文件中的“ dependencies”拼写错误。希望对您有所帮助。

答案 4 :(得分:0)

如果您的目录中有package-lock.json文件,则您尝试运行npm install ...删除package-lock.json文件,然后再次运行npm install,这将生成所需的所有文件和文件夹。 / p>

答案 5 :(得分:0)

您可能已经在使用带有package.json的应用程序,只需将其粘贴到新项目中,然后输入命令npm install

答案 6 :(得分:0)

同意@AnthonyAstige-我有一个同样的问题,就是没有创建node_modules文件夹...至少我是这么想的。在运行npm install express --save之前,我已经将要使用的文件夹单击/拖放到VSCode中。 @brk让我在其他目录/文件夹中查找,但发现node_modules文件夹的路径在我的主目录中,而不是我拖到VSCode中的文件夹。

故事的故事...在运行安装之前,请确保您位于正确的目录(即项目的根目录)中。我知道,菜鸟犯错,但这显然是一个广泛讨论的话题。

答案 7 :(得分:0)

<块引用>

尝试这些可能的解决方案。

1. Delete the node_modules folder and also delete the package-lock.json 
   file(if already present).
2. Clear the cache using npm cache clean --verify.
3. And then run npm install again.
<块引用>

如果缺少 package.json

   1. run npm init. It will create the package.json file on the fly for you.
   2. After this proceed as written in 1st Solution.
<块引用>

这个错误可能是由许多不同的事情引起的。也许您的全局包以某种方式损坏了。

1 Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. 
  It is a much stable version for development. This should also change your NPM 
  version so that may also help.

2.Delete the package-lock.json file(if already present).

3 Force clear cache npm cache clean --force

4 You can also try clearing your %temp% and %roaming% AppData/npm-cache

5 Run npm install --force.

4 if this error still occurs, consider using another shell.