问题
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?
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"
}
}
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)
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:
- Manually creating the node_modules/ directory before running npm install
- Checking directory permissions
- Other stackoverflow articles
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).
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.
回答1:
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
来源:https://stackoverflow.com/questions/30223199/npm-install-does-not-install-any-dependencies-from-package-json