When you did the command npm init
, there were probably some relevant questions you needed to answer. Specifically, the name of your module. When you use npm init
, it assumes you want the name of the module you're creating to be called the name of the folder it is in.
So it's not the name of the folder that is stopping you from installing the dependency, it is the name of the npm module that you are creating.
Open the resulting package.json
within your hapi
directory, and rename the module to something other than hapi
. Here's an example 'package.json' that works, even when residing in a folder called hapi:
{
"name": "hapi-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hapi": "^7.5.2"
}
}
Added Note
I've not been able to find any documentation thus-far explaining this phenomena in the context of npm; though it is a bit of a no-brainer. Requiring modules with the same name within the same application would conflict with the CommonJS philosophy.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…