node.js npm install 不创建 node_modules 目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21250849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install doesn't create node_modules directory
提问by Connor Leech
I am trying to do a homework for a mongodb uni course. They gave us some files, instructions are:
我正在尝试为 mongodb uni 课程做作业。他们给了我们一些文件,说明是:
run npm install mongodbthen node app.js
npm install mongodb然后运行node app.js
for some reason npm install does not create a node_modules directory but I don't see any build errors:
出于某种原因, npm install 没有创建 node_modules 目录,但我没有看到任何构建错误:
mongo-uni/hw1-2$ npm install mongodb
npm WARN package.json [email protected] path is also the name of a node core module.
npm http GET https://registry.npmjs.org/mongodb
npm http 304 https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/bson/0.2.5
npm http GET https://registry.npmjs.org/kerberos/0.0.3
npm http 304 https://registry.npmjs.org/kerberos/0.0.3
npm http 304 https://registry.npmjs.org/bson/0.2.5
> [email protected] install /home/jasonshark/node_modules/mongodb/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
make: Entering directory `/home/jasonshark/node_modules/mongodb/node_modules/kerberos/build'
SOLINK_MODULE(target) Release/obj.target/kerberos.node
SOLINK_MODULE(target) Release/obj.target/kerberos.node: Finished
COPY Release/kerberos.node
make: Leaving directory `/home/jasonshark/node_modules/mongodb/node_modules/kerberos/build'
> [email protected] install /home/jasonshark/node_modules/mongodb/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
make: Entering directory `/home/jasonshark/node_modules/mongodb/node_modules/bson/build'
CXX(target) Release/obj.target/bson/ext/bson.o
make: Leaving directory `/home/jasonshark/node_modules/mongodb/node_modules/bson/build'
[email protected] ../../../node_modules/mongodb
├── [email protected]
└── [email protected]
mongo-uni/hw1-2$ node app.js
Failed to load c++ bson extension, using pure JS version
'No document found'
回答by CESCO
npm init
npm init
It is all you need. It will create the package.json file on the fly for you.
这就是你所需要的。它将为您即时创建 package.json 文件。
回答by Piyush Sagar
NPMhas created a node_modulesdirectory at '/home/jasonshark/' path.
NPM在“/home/jasonshark/”路径下创建了一个node_modules目录。
From your question it looks like you wanted node_modulesto be created in the current directory.
从您的问题来看,您似乎希望在当前目录中创建node_modules。
For that,
为了那个原因,
- Create project directory:
mkdir <project-name> - Switch to:
cd <project-name> - Do:
npm initThis will create package.json file at current path Open package.json& fill it something like below
{ "name": "project-name", "version": "project-version", "dependencies": { "mongodb": "*" } }Now do :
npm installORnpm update
- 创建项目目录:
mkdir <project-name> - 切换到:
cd <project-name> - 做:
npm init这将在当前路径创建 package.json 文件 打开package.json并填写如下内容
{ "name": "project-name", "version": "project-version", "dependencies": { "mongodb": "*" } }现在做:
npm install或npm update
Now it will create node_modulesdirectory under folder 'project-name' you created.
现在它将在您创建的文件夹“ project-name”下创建node_modules目录。
回答by cheshireoctopus
See @Cesco's answer: npm initis really all you need
见@Cesco 的回答:npm init这真的是你所需要的
I was having the same issue - running npm install somePackagewas not generating a node_modulesdir.
我遇到了同样的问题 - 运行npm install somePackage没有生成node_modules目录。
I created a package.jsonfile at the root, which contained a simple JSON obj:
我package.json在根目录创建了一个文件,其中包含一个简单的 JSON obj:
{
"name": "please-work"
}
On the next npm installthe node_modulesdirectory appeared.
在接下来npm install的node_modules目录出现。
回答by wendyh
If you have a package-lock.jsonfile, you may have to delete that file then run npm i. That worked for me
如果您有package-lock.json文件,则可能必须删除该文件,然后运行npm i. 那对我有用
回答by Farreal
As soon as you have run npm initand you start installing npm packages it'll create the node_modualsfolder after that first install
一旦你运行npm init并开始安装 npm 包,它会node_moduals在第一次安装后创建文件夹
e.g
例如
npm init
npm init
(Asks you to set up your package.json file)
(要求你设置你的 package.json 文件)
npm install <package name here> --save-dev
npm install <package name here> --save-dev
installs package & creates the node modules directory
安装包并创建节点模块目录
回答by wantrapreneur
I ran into this trying to integrate React Native into an existing swift project using cocoapods. The FB docs (at time of writing) did not specify that npm install react-nativewouldn't work without first having a package.jsonfile. Per the RN docs set your entry point: (index.js)as index.ios.js
我在尝试使用 cocoapods 将 React Native 集成到现有的 swift 项目中时遇到了这个问题。FB 文档(在撰写本文时)没有指定npm install react-native如果没有package.json文件就无法工作。根据 RN 文档将您设置entry point: (index.js)为index.ios.js
回答by Abhijeet Navgire
For node_modules you have to follow the below steps
对于 node_modules,您必须按照以下步骤操作
1) In Command prompt -> Goto your project directory.
1) 在命令提示符 -> 转到您的项目目录。
2) Command :npm init
2)命令:npm init
3) It asks you to set up your package.json file
3) 它要求你设置你的 package.json 文件
4) Command: npm installor npm update
4)命令:npm install或npm update

