NPM not creating .bin directory

2020-06-30 04:35发布

问题:

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"
  }
}

回答1:

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



回答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.



回答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?



回答4:

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


回答5:

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!