npm install doesn't create node_modules directory

坚强是说给别人听的谎言 提交于 2019-11-28 22:24:43

npm init

It is all you need. It will create the package.json file on the fly for you.

Piyush Sagar

NPM has created a node_modules directory at '/home/jasonshark/' path.

From your question it looks like you wanted node_modules to be created in the current directory.

For that,

  1. Create project directory : mkdir <project-name>
  2. Switch to : cd <project-name>
  3. Do : npm init //This will create package.json file at current path
  4. Open package.json & fill it something like below

    { "name": "project-name", "version": "project-version", "dependencies": { "mongodb": "*" } }

  5. Now do : npm install OR npm update

Now it will create node_modules directory under folder 'project-name' you created.

See @Cesco's answer: npm init is really all you need


I was having the same issue - running npm install somePackage was not generating a node_modules dir.

I created a package.json file at the root, which contained a simple JSON obj:

{
    "name": "please-work"
}

On the next npm install the node_modules directory appeared.

If you have a package-lock.json file, you may have to delete that file then run npm i. That worked for me

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-native wouldn't work without first having a package.json file. Per the RN docs set your entry point: (index.js) as index.ios.js

As soon as you have run npm init and you start installing npm packages it'll create the node_moduals folder after that first install

e.g

npm init

(Asks you to set up your package.json file)

npm install <package name here> --save-dev

installs package & creates the node modules directory

For node_modules you have to follow the below steps

1) In Command prompt -> Goto your project directory.

2) Command :sudo npm init

3) It asks you to set up your package.json file

4) Command: sudo npm install or sudo npm update

Note:: If any permission issue persist while above steps please give folder permission as given below

sudo chmod -R 777 <folder name>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!