NPM安装不会从package.json安装任何依赖项 [英] NPM install does not install any dependencies from package.json

查看:312
本文介绍了NPM安装不会从package.json安装任何依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Node.js项目的根目录运行 npm install ,因为我想安装位于 package.json 中的所有项目依赖项. .但是,当我在命令行中运行 npm install 时,它显示了据报道已安装的依赖项列表,但是当我转到该目录并搜索子目录 node_modules/,它不存在.因此,这些依赖项并没有真正安装,正如我尝试运行 npm start 所证明的那样,它将开始引发有关缺少模块的错误.我在做什么错了?

I am trying to run npm install from the root of my Node.js project, because I want to install all of my project dependencies located in my package.json. However, when I run npm install in the command line, it shows a list of the dependencies that it reportedly installed, however when I go to that directory and search for the subdirectory node_modules/, it does not exist. Therefore, those dependencies were not really installed, as is evidenced when I try to run npm start, it will start throwing errors about modules missing. What am I doing wrong?

这是我的 package.json 的副本(出于隐私目的删除了详细信息):

This is a copy of my package.json (specifics removed for privacy):

{
  "name": "xxxxxxxxx",
  "version": "x.x.x",
  "description": "xxxxxxxxx",
  "main": "xxxxxxxxx.js",
  "scripts": {
    "start": "node xxxxxxxxx.js",
    "lint": "jshint **/**/*.js --reporter=node_modules/jshint-stylish/stylish.js",
    "test": "mocha test/"
  },
  "pre-commit": [
    "lint",
    "test"
  ],
  "repository": {
    "type": "git",
    "url": "https://xxxxxxxxx.git"
  },
  "author": "xxxxxxxxx",
  "license": "xxxxxxxxx",
  "dependencies": {
    "bluebird": "^2.9.13",
    "boom": "^2.6.1",
    "good": "^5.1.2",
    "good-console": "^4.1.0",
    "hapi": "^8.2.0",
    "hapi-swagger": "^0.6.4",
    "joi": "^5.1.0",
    "lodash": "^3.3.1",
    "lodash-deep": "^1.5.3",
    "lout": "^6.2.0",
    "request": "^2.55.0"
  },
  "devDependencies": {
    "chai": "^2.0.0",
    "jshint-stylish": "^1.0.2",
    "mocha": "^2.1.0",
    "pre-commit": "^1.0.7"
  }
}

如前所述,此处列出的所有依赖项均以绿色文本显示在命令提示符下,向我表明它们已下载.但是,由于 node_modules/甚至不存在,因此未下载它们.命令提示符如下:

As noted, all of the dependencies listed here show up in command prompt with the green text, indicating to me that they were downloaded. However, they were not downloaded, as the node_modules/ does not even exist. The command prompt looks like this:

C:\development>npm install
npm http GET https://registry.npmjs.org/boom
npm http GET https://registry.npmjs.org/good-console
npm http GET https://registry.npmjs.org/bluebird
npm http GET https://registry.npmjs.org/good
npm http GET https://registry.npmjs.org/joi
npm http GET https://registry.npmjs.org/hapi-swagger
npm http GET https://registry.npmjs.org/lout
npm http GET https://registry.npmjs.org/hapi
npm http GET https://registry.npmjs.org/lodash-deep
npm http GET https://registry.npmjs.org/chai
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/jshint-stylish
npm http GET https://registry.npmjs.org/mocha
npm http GET https://registry.npmjs.org/pre-commit
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/good-console
npm http 304 https://registry.npmjs.org/boom
npm http 304 https://registry.npmjs.org/bluebird
npm http 304 https://registry.npmjs.org/good
npm http 304 https://registry.npmjs.org/hapi-swagger
npm http 304 https://registry.npmjs.org/hapi
npm http 304 https://registry.npmjs.org/lodash-deep
npm http 304 https://registry.npmjs.org/chai
npm http 304 https://registry.npmjs.org/joi
npm http 304 https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/lout
npm http 304 https://registry.npmjs.org/jshint-stylish
npm http 304 https://registry.npmjs.org/mocha
npm http 304 https://registry.npmjs.org/pre-commit
npm http 304 https://registry.npmjs.org/request

C:\development>ll
05/13/2015  12:32 PM    <DIR>          .
05/13/2015  12:32 PM    <DIR>          ..
05/12/2015  05:24 PM                93 .gitignore
05/12/2015  05:24 PM                15 .jshintignore
05/12/2015  05:24 PM             3,957 .jshintrc
05/12/2015  05:24 PM                36 .npmrc
05/12/2015  05:24 PM    <DIR>          config
05/12/2015  05:24 PM             1,363 xxxxx.json
05/12/2015  05:24 PM    <DIR>          lib
05/12/2015  05:24 PM             1,201 package.json
05/12/2015  05:24 PM             1,113 readme.md
05/12/2015  05:24 PM             2,046 xxxxx.js

C:\development>npm start

module.js:340
    throw err;
          ^
Error: Cannot find module 'hapi'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\path)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

请注意,上面没有子目录 node_modules/,以及在前面的命令提示符中列出模块'hapi'时找不到该模块的事实如已下载.

Notice above that no subdirectory node_modules/ exists above, as well as the fact that it cannot find the module 'hapi' when it was listed in the command prompt earlier as having been downloaded.

到目前为止,我尝试过的是:

What I have tried so far is:

  • 在运行 npm install
  • 之前手动创建 node_modules/目录.
  • 检查目录权限
  • 其他stackoverflow文章

但是我仍然没有成功.请注意,最接近我的问题的stackoverflow是 npm install不会安装任何依赖项,但这与以下事实不同:该帖子上的答案"不能解决我的问题(本来是删除目录 node_modules/,但我的目录根本不存在).

But I have still had no success. Note that the closest stackoverflow to my question is npm install doesn't install any dependencies, but this differs in the fact that the "answer" on that post does not solve my problem (which was to delete the directory node_modules/, but mine doesn't even exist).

我能够在我拥有的其他Node.js项目中运行 npm install ,并成功地从其 package.json 安装依赖项.我只是无法使这个示例正常工作.

I am able to run npm install in other Node.js projects that I have, with success in installing dependencies from their package.json. I just can't get this example to work.

推荐答案

监视npmrc中的根文件夹. ..通常会在文件夹中没有package.json文件的情况下发生..第二个是从您的日志中获取的,我看不到模块下载的信息..可能无法访问npm或某些东西..将npm注册表comfig设置为http,然后再试一次.更改路径D:或其他内容.如果发生这种情况,请使用npm引发错误

Watch for root folder in npmrc.. May be all your dependencies are downloaded to root folder.. Npm does this some times.. I too encountered this problem... Mostly it happens when no package.json file in the folder.. 2nd would be from your logs I don't see the modules downloaded info.. May it couldn't access npm or some thing.. Set npm registry comfig to http and try once again. Change your path D: or some thing.. If it happens there raise a bug with npm

这篇关于NPM安装不会从package.json安装任何依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆