43

I'm using npm v1.4.4 and node v0.10.25 on Mac OS X 10.9.2.

I've recently upgraded node and npm, and now npm install is no longer creating the .bin directory in node_modules.

I've deleted node_modules, tried npm install again, but the directory and binaries are never created.

Does anybody have any ideas as to why this is happening?

Here is my package.json:

{
  "name": "redacted",
  "author": {},
  "description": "redacted",
  "dependencies": {
  },
  "devDependencies": {
    "karma": "*",
    "karma-coverage": "0.1.2",
    "karma-junit-reporter": "*",
    "karma-coffee-preprocessor": "~0.1",
    "grunt": "^0.4.2",
    "grunt-contrib-requirejs": "^0.4.3",
    "grunt-contrib-concat": "^0.3.0",
    "grunt-contrib-sass": "^0.7.2",
    "grunt-contrib-htmlmin": "^0.2.0",
    "grunt-contrib-cssmin": "^0.7.0",
    "grunt-contrib-coffee": "^0.10.1",
    "grunt-contrib-uglify": "^0.3.3",
    "grunt-contrib-jst": "^0.5.1",
    "grunt-contrib-qunit": "^0.4.0",
    "grunt-contrib-jshint": "^0.8.0",
    "grunt-contrib-watch": "^0.5.3",
    "grunt-contrib-jasmine": "^0.6.1",
    "grunt-contrib-compress": "^0.6.1",
    "grunt-contrib-handlebars": "^0.6.1",
    "grunt-contrib-less": "^0.9.0",
    "grunt-contrib": "^0.9.0"
  }
}
Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
Gaz
  • 1,570
  • 2
  • 17
  • 22
  • Could you share your `package.json`? – saladinxu Mar 12 '14 at 06:22
  • I've updated the question to include the package.json contents. – Gaz Mar 12 '14 at 06:25
  • 1
    Quick hack: `ls node_modules | xargs -n1 npm install` – Orwellophile Sep 07 '15 at 04:03
  • I had this problem because my disk memory was fulled – mqklin Aug 12 '16 at 03:11
  • 1
    Did you find a solution to this? I am having this issue when running calling `npm install` during a Jenkins build. The build agent is a Docker container, and `npm install` is being called inside a directory that was mounted from the host. Could any of these factors cause the silent failure of `node_modules/.bin` creation? – Cameron Hudson Feb 11 '20 at 18:25
  • FWIW - i had this issue. i removed the entire node_modules directory and did `npm ci` and it started working. not sure if either did anything, or it randomly started working. – Cory Mawhorter Mar 13 '21 at 21:03

7 Answers7

27

I know this is an old post but I experienced the same issue recently. I had copied files from an existing project including package.json and package-lock.json. The package-lock.json was what prevented the node_module/.bin directory from being created. The solution was to delete the node_modules directory and package-lock.json and run npm install again

Balocodes
  • 577
  • 7
  • 6
  • 2
    That did it for me! Thanks – iansari Jan 09 '21 at 18:11
  • 2
    Who knew that the `package-lock.json` would interfere with correct generation of `node_modules/.bin/`?! Well done! My `npm install` would fail after building only 50% of `.bin` so when other run-scripts were executed the binaries would be missing. SO ODD! Deleted `node_modules` & `package-lock.json` and BAM it worked! Thanks!!! – codejedi365 May 13 '21 at 21:47
  • 1
    Fantastic! I deleted the package-lock.json, but not node_modules. Then saw your answer here and deleted both, and now it works! Thanks!! – redfox05 Sep 10 '21 at 10:04
  • After deleting `package-lock.json` then npm wouldn't even create a `node_modules` folder on `npm install` :/ – derpedy-doo Jul 17 '23 at 11:58
4

The ./node_modules/.bin directory is where npm creates links to a node package's binary. From https://docs.npmjs.com/files/folders#executables

Executables

When in global mode, executables are linked into {prefix}/bin on Unix, or directly into {prefix} on Windows.

When in local mode, executables are linked into ./node_modules/.bin so that they can be made available to scripts run through npm. (For example, so that a test runner will be in the path when you run npm test.)


The package.json you pasted above do not have a bin section. Take a look at this example from npm's package.json

{
  "version": "1.4.9",
  "name": "npm",
  "publishConfig": {
    "proprietary-attribs": false
  },
  "description": "A package manager for node",
  ...
  ...
  "main": "./lib/npm.js",
  "bin": "./bin/npm-cli.js",
  "dependencies": {
    "abbrev": "~1.0.4",
    "ansi": "~0.2.1",
    ...
    ...

Specifically the line "bin": "./bin/npm-cli.js" will tell npm to create a link at ./node_modules/.bin/npm to node_modules/npm/npm-cli.js

Dexter
  • 2,462
  • 4
  • 24
  • 28
Hanxue
  • 12,243
  • 18
  • 88
  • 130
  • Presumably one of the dependencies does create `node_module/.bin` — don't grunt and karma both do that? – Lee Goddard Oct 15 '15 at 12:30
  • 1
    No `package.json` _requires_ a `bin` section. The .bin dir should still be created. – Auspex Feb 14 '19 at 21:32
  • 2
    The link referenced in this answer is broken, and I don't seem to find any entry in the actual docs explaining how npm handles binaries and the `.bin` folder. This is an entry barrier for anyone who's new on this. Any ideas about where can I find proper documentation on this? – Amy Pellegrini Jun 06 '19 at 11:13
  • 1
    Oh, no worries, I find it: https://docs.npmjs.com/files/folders#executables – Amy Pellegrini Jun 06 '19 at 11:18
  • 2
    @Auspex No, `package.json` does not require a `bin` section. Run `npm init` and install something, and you will see. – Cameron Hudson Feb 11 '20 at 18:04
3

Seems that all your dependencies are dev dependencies. Could you see if your NODE_ENV environment variable is set to production now? If yes you will need to change it back.

Also, any error happened during installation?

saladinxu
  • 372
  • 1
  • 2
  • 12
  • NODE_ENV is empty. If I move them to dependencies, or use --dev, the result it the same - no .bin directory. No errors at all, everything looks fine. – Gaz Mar 12 '14 at 07:20
  • Have you tried starting from a clean project? Also see if this helps: https://github.com/npm/npm/issues/2566 – saladinxu Mar 12 '14 at 07:45
  • A fresh project behaves in the same way. That was the first link I found when trying to diagnose the problem. It didn't help. – Gaz Mar 12 '14 at 08:08
2

In my case I had webpack running in watch mode in another console window. I did not get any errors during npm install so it took me a moment to notice.

  1. Ensure the dependencies are not in use, such as karma running tests or webpack running in watch mode
  2. Delete the dependency folders, such as node_modules/karma, or the entire node_modules folder. NPM does not seem to create symlink files in .bin folder if dependency folder already exists.
  3. Retry npm install

With NPM 6.7.0.

angularsen
  • 8,160
  • 1
  • 69
  • 83
  • 1
    Sometimes one just needs to blow away the entire `node_modules` folder to get things working... – Phil Jun 25 '20 at 12:01
2

If all packages installed, only the .bin is gone.

you can just run npm rebuild

flyflydogdog
  • 307
  • 3
  • 10
0

Not really an answer to your question, but because I had a similar situation: I run npm with the --no-bin-links option on my VM so my windows host doesn't complain. And then later I don't find the bin links folder... duh!

Tominator
  • 1,224
  • 3
  • 19
  • 37
-1

This could happen because of the broken npm. Try following command from the npm troubleshooting and it should just work fine.

curl -L https://www.npmjs.org/install.sh | sh
samarth
  • 3,866
  • 7
  • 45
  • 60