我正在尝试从我的Node.js项目的根目录运行 npm install ,因为我想安装位于 package.json 中的所有项目依赖项。但是,当我在命令行中运行 npm install 时,它会显示它报告安装的依赖项列表,但是当我转到该目录并搜索子目录 node_modules / 时强>,它不存在。因此,这些依赖项并未真正安装,正如我尝试运行 npm start 时所证明的那样,它将开始抛出有关模块丢失的错误。我做错了什么?
这是我的 package.json 的副本(隐私细节被移除):
{
"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 / 甚至不存在,因此未下载它们。命令提示符如下所示:
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 / ,以及它在列出时无法找到&#39; hapi&#39; 模块的事实在下载之前的命令提示符中。
到目前为止我尝试的是:
但我仍然没有成功。请注意,与我的问题最接近的stackoverflow是npm install doesn't install any dependencies,但这与&#34; answer&#34;在那篇文章中没有解决我的问题(这是删除目录 node_modules / ,但我甚至不存在)。
我能够在我拥有的其他Node.js项目中运行 npm install ,并成功地从 package.json 安装依赖项。我无法让这个例子起作用。
答案 0 :(得分:0)
在npmrc中查看根文件夹..可能是你的所有依赖项被下载到根文件夹.. Npm这样做了一些..我也遇到过这个问题...大多数情况下,当文件夹中没有package.json文件时..第二个将来自你的日志我没有看到模块下载信息..可能它无法访问npm或一些东西..将npm注册表设置设置为http并再次尝试。改变你的路径D:或某些东西..如果它发生了那么就会出现npm的错误