【发布时间】:2015-07-25 05:38:43
【问题描述】:
我正在尝试从我的 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/ 存在,以及它在前面的命令提示符中列出时找不到模块 'hapi' 的事实已下载。
到目前为止我尝试过的是:
- 在运行 npm install 之前手动创建 node_modules/ 目录
- 检查目录权限
- 其他 stackoverflow 文章
但我仍然没有成功。请注意,与我的问题最接近的 stackoverflow 是 npm install doesn't install any dependencies,但不同之处在于该帖子上的“答案”并没有解决我的问题(即删除目录 node_modules/,但是我的甚至都不存在)。
我能够在我拥有的其他 Node.js 项目中运行 npm install,并成功地从他们的 package.json 安装依赖项。我只是无法让这个例子工作。
【问题讨论】:
-
你能看到使用
npm ls安装的依赖项吗?看起来npm install被某种原因打断了。
标签: node.js npm package.json