我发现当我在本机项目的根目录下运行npm install时,它总是向我显示警告:
npm WARN enoent ENOENT:没有这样的文件或目录,打开'/Users/chen/Documents/react-native/project/node_modules/node_modules/package.json'
但是我们知道package.json应该在node_modules文件夹下
这是项目根目录中的 package.json
{
"name": "project",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"bundle-ios": "node node_modules/react-native/local-cli/cli.js bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ./ios/bundle/index.ios.jsbundle --assets-dest ./ios/bundle"
},
"dependencies": {
"react": "~15.4.0-rc.4",
"react-native": "0.40.0",
"react-native-elements": "^0.9.0",
"react-native-scrollable-tab-view": "^0.7.0",
"react-native-swiper": "^1.5.4",
"react-native-vector-icons": "^4.0.0"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.1.0",
"react-test-renderer": "~15.4.0-rc.4"
},
"jest": {
"preset": "react-native"
}
}
在运行npm install之后,这个json的一切正常,库将附加在依赖项中 .
并且在node_modules foloder中还有另一个 package.json
,当我运行npm install时,这个json不会更新,错误说它指向 node_modules/node_modules/package.json
,当然不存在这个文件
{
"dependencies": {
"react-native-scrollable-tab-view": "^0.7.0",
"react-native-swiper": "^1.5.4",
"react-native-vector-icons": "^4.0.0",
"react-native-elements": "^0.9.0"
}
}
那么npm install如何找到错误的路径?
2 回答
package.json
模块应该出现在项目的root
目录中 . 这是,如果要为项目安装所有npm
依赖项 .实际上,当您运行
npm install
时,它会搜索package.json
文件,并安装该文件中写入的所有dependencies
. 因此,无论您在哪里运行npm install
,该目录中都应该有一个package.json
文件 .因此,为简单起见,我们将
package.json
文件保留在project
的根目录下,以便npm
一次性安装该项目所需的所有依赖项 .Update:
每个
node module
都有自己的package.json
文件和node_modules
文件夹,这就是它的工作方式 .package.json
包含该模块所需的所有dependencies
,node_modules
文件夹中包含这些模块 . 再次,如果你再深入一级,你会发现另一个package.json文件 . 所以,所有这些package.json
都包含特定module
所需的依赖项 .Try to go inside the node_modules folder and explore it, you will understand it better.
项目根目录中有一个package.json .
然后node_modules下的每个模块都有一个 .
但我不认为你应该在node_modules文件夹中有一个package.json