NPM not creating .bin directory - node.js

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

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

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

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?

If all packages installed, only the .bin is gone.
you can just run npm rebuild

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.
Ensure the dependencies are not in use, such as karma running tests or webpack running in watch mode
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.
Retry npm install
With NPM 6.7.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!

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

Related

How to ignore scoped packages' node_modules/ directory during npm install?

I have a repository containing a package.json which contains scoped dependencies. I also have an .npmignore file intended to whitelist all files and subdirectories in dist/. The problem is all of the scoped dependencies are included when running npm install #private/a another repository. This includes both private npm packages and public packages such as #uirouter.
package.json:
{
"name": "#private/a",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git#bitbucket.org/private/a.git"
},
"author": "",
"license": "ISC",
"homepage": "https://bitbucket.org/private/a#readme",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-angular-embed-templates": "^2.3.0",
"gulp-concat": "^2.6.1",
"gulp-jshint": "^2.0.4",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.0.0",
"gulp-uglify": "^2.0.0",
"jshint": "^2.9.4"
},
"dependencies": {
"#private/b": "^1.0.0",
"#private/c": "^1.0.0"
}
}
.npmignore
**
!dist/**
Despite these two files when I run npm install #private/a --save within another repository it is installing the dependency along with all it's scoped dependencies:
/node_modules/#private/a/dist/index.js
/node_modules/dist/css/styles.css
/node_modules/#private/a/node_modules/#private/b
/node_modules/#private/a/node_modules/#private/c
package.json
It should only be this:
/node_modules/#private/a/dist/index.js
/node_modules/dist/css/styles.css
package.json
How can I achieve this? I have tried different variations of the .npmignore but have not had any luck.
.npmignore is irrelevant to what you are trying to do. This file only decides which parts of your npm package code ends up in npm registry. So it is working as advertised.
Your problem must be in your npmconfig or because of using an older version of npm. The latest version installs stuff as so:
/node_modules/#private/a/dist/index.js
/node_modules/#private/b/...
/node_modules/#private/c/...
package.json
I have verified that this is happening with latest npm. But there used to be a time when npm installed dependencies into a nested structure. See this for example. So I suggest:
Making sure you have latest node and npm.
Making sure your npm config is not forcing legacy bundling. Run npm get legacy-bundling. Make sure this is false.
There are few cases where the nesting of dependencies happens legitimately even with the latest npm. See this. But I am guessing your problem is not due to this. You can test by simply doing npm install #private/a in an empty folder.
Node will install your package files along with all the dependencies declared under dependencies field.
How the dependencies tree is build, depends on which version of npm do you use.
If your package doesn't need those dependencies to run, it means they are just dev dependencies and you can safely list them under devDependencies field.
Dev dependencies are only installed when you run an npm install inside the plugin directory.
You need to lock your dependency. You might want to check out npm shrinkwrap.

npm install error code 128

I am receiving the following error when trying to run npm install after a fresh install of Node and Git
Anyone have any idea what could be causing it, and what to do to fix it?
package.json (removed company details)
{
"name": "xxx",
"version": "1.0.0",
"description": "xxx",
"engines": {
"node": "5.0.0",
"npm": "3.3.9"
},
"repository": "xxx",
"private": true,
"license": "UNLICENSED",
"dependencies": {
"dijit": "https://github.com/dojo/dijit.git#1.10.4",
"dojo": "1.10.4",
"fg-dialog": "0.1.5",
"politespace": "0.1.4",
"shoestring": "1.0.3"
},
"devDependencies": {
"body-parser": "^1.14.1",
"chalk": "^1.1.1",
"compression": "^1.6.0",
"del": "^2.0.2",
"dojo-util": "https://github.com/dojo/util.git#1.10.4",
"express": "^4.13.3",
"glob": "^5.0.15",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-git": "^1.6.0",
"gulp-html-minifier": "^0.1.6",
"gulp-jsbeautifier": "^1.0.1",
"gulp-jshint": "^1.11.2",
"gulp-jshint-xml-file-reporter": "^0.5.1",
"gulp-jsonminify": "^1.0.0",
"gulp-replace": "^0.5.4",
"gulp-task-listing": "^1.0.1",
"gulp-uglify": "^1.4.1",
"gulp-util": "^3.0.6",
"gulp-zip": "^3.0.2",
"intern": "https://github.com/theintern/intern.git",
"jshint-stylish": "^2.0.1",
"merge-stream": "^1.0.0",
"minimist": "^1.2.0",
"open": "^0.0.5",
"q": "^1.4.1",
"request": "^2.65.0",
"require-dir": "^0.3.0",
"run-sequence": "^1.1.2",
"selenium-standalone": "^4.6.3"
},
"scripts": {
"postinstall": "gulp install"
}
}
A recommended first step is to use the latest npm:
npm install -g npm
(You may need sudo). You are using npm 2.x, the latest is 3.5.x.
In my case I had just upgraded npm and package-lock.json was trying to install one of the project's packages from an unavailable git commit version.
Deleting and letting npm re-create the file package-lock.json resolved the issue.
rm package-lock.json
Note: It looks like package-lock.json maintains more details about the node_modules tree, so in a complicated/version specific project it may be important to isolate the specific line(s) causing the issue, versus just delete the package-lock.json file.
https://docs.npmjs.com/files/package-lock.json
The error points at revisioning, specifically usage of 1.10.4. Check that the BitBucket repos for dijit.git and util.git are setup with tagging. More information on versioning/tagging at Atlassian: https://confluence.atlassian.com/bitbucket/use-repo-tags-321860179.html.
If you're using SSH with a saved password, the references to your personal repositories will need to connect via SSH using the format below.
git+ssh://git#bitbucket.org/{user}/{repository}.git
I had the same npm error code 128 but it also had a reference to the debug.log file in the npm-cache which revealed the real problem.
Two of the dependencies in the package.json were pointing to private repositories directly that I don't have access to.
Once I fixed that (details here) I was able to run npm install successfully. Note: no reinstall or update of npm required!
Firstly, I deleted the npm and npm-cache directories that locate in c:\myUser\AppData\Roaming.
Then, I excuted npm install -g npm. That resolved my problem.
I was also getting the same error on windows 10 and I fixed it by adding the ssh key again in the GitHub by generating using the following URL: https://help.github.com/enterprise/2.13/user/articles/connecting-to-github-with-ssh/
to check the Existing key use following commands:
Open Git Bash. press the windows button and search for Git Bash.
Enter ls -al ~/.ssh to see if existing SSH keys are present
Check the directory listing to see if you already have a public SSH key.
if key files exist it will list them(using default file name) like :
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
After that, you have to make sure that ssh-agent is running
you can use eval $(ssh-agent -s) command to run the ssh-agent
After this, you have to add this existing key using the command: ssh-add ~/.ssh/id_rsa
now as you file is added you can get key to the clipboard using command clip < ~/.ssh/id_rsa.pub
go to GitHub site and click on settings in top right corner and add this ssh key to gitHub.
restart the command prompt and error will be fixed.
hope this will help someone.
you must use cmd as adminstrator in windows, or add sudo in linux
Remove the node_modules folder and delete package-lock.json file. Then run following commands,
npm cache clean --force
npm install
I used git Bash instead of cmd and it worked.
First Step
rm package-lock.json
rm -rf node_modules/
npm install -g npm
If above does not works, try changing the node version to previous versions.
For me the solution was as simple as executing this on the git bash:
export GIT_SSH_COMMAND='ssh'
My npm probably was using some other installed ssh program from somewhere on my pc and that one wasn't using the right credentials.
Saw this error while trying to install a package with quotation marks around the package name:
npm i 'foobar'
should be
npm i foobar

npm WARN package.json Stock#0.0.1 No repository field

I have a project in a personal private git, I downloaded in another computer and when trying to download the packages in packages.json i got this error message:
pablo#debian:~/Documents/clients/stock$ npm install
npm WARN package.json Stock#0.0.1 No repository field.
npm WARN package.json Stock#0.0.1 No README data
This is the content of the packages.json
{
"name": "Stock",
"version": "0.0.1",
"description": "Stock App",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-execute": "^0.2.2",
"socket.io": "latest",
"mysql": "latest",
"express": "latest",
"path": "latest",
"express-session": "latest",
"cookie-parser": "latest",
"ejs": "latest"
},
"dependencies": {
"socket.io": "~1.3.7",
"body-parser": "~1.14.1"
}
}
What can I do, to packages to download, and why in my other computer I don't get this error?
These warnings are just warnings, and don't indicate anything reason that the dependencies would not have downloaded.
The package.json file shown is working perfectly for me. To debug your issue, try removing the node_modules folder and running npm install again. Note that if the packages are already in the node_modules folder, npm install won't download them again.
If you want to fix the warnings:
Before devDependencies, add a repository option; i.e. something like:
"repository": {
"type": "git",
"url": "[git-url-of-your-project]"
},
The URL doesn't have to be a github one, just whatever you use to git
clone the project on another computer.
Add a file called README or README.md and write a few words about what the project is in it.
Mark your application as private to suppress all warnings by adding "private": true
{
"name": "Stock",
"version": "1.0.1",
"private": true
}
I found removing the node_modules folder and doing 'npm install' from fresh seemed to fix my issues.
Just add your package.json file from
C:\Program Files\nodejs\node_modules\npm
to
C:\Windows\System32
and everything will be fine and working. Hope it helps.

node.js - how to install a single dependency globally?

My package.json file looks like this:
{
"name": "tets",
"version": "1.0.0",
"devDependencies": {
"chai": "^3.0.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.0.3",
"gulp-minify-css": "^1.2.0",
"gulp-plumber": "^1.0.1",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.2.0",
"karma": "^0.12.0",
"karma-chai": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.0",
"mocha": "^2.2.5"
}
}
To install this locally I would run npm install and to install all dependencies globally I would run npm install -g. I only want to install gulp globally, though. Is there any way to accomplish this?
As a caveat, I've integrated a gulpfile into a .NET project and have it running via a post-build event. As a pre-build event, I'm executing npm install to ensure everything is setup correctly. My hope is that any code to install only gulp globally can be added to the package.json file so I can keep my pre-build event to just npm install. Unless adding npm install gulp -g to my pre-build event is acceptable...
So #FaridNouriNeshat pointed me to a solution where gulp is accessed locally which is probably the most appropriate thing to do rather than globally install it into someone's machine. In my case, I altered my post-build event in my .NET app to point to the local install of gulp rather than a global install.
"$(SolutionDir)\Gorman.Abe.Web\node_modules\.bin\gulp" styles scripts

npm doesn't install devDependencies recursively

There is connect-assets in my package.json's dependencies. And its package.json looks like:
"dependencies": {
"connect-file-cache": "0.2.4",
"mime": "1.2.2",
"snockets": "1.3.6",
"underscore": "1.1.7"
},
"devDependencies": {
"async": "0.1.14",
"coffee-script": "~1.3.1",
"connect": "1.8.5",
"nib": "0.2.0",
"bootstrap-stylus": "0.2.0",
"nodeunit": "0.5.4",
"stylus": "0.22.2",
"request": "2.1.1",
"watchit": "0.0.4",
"less": "1.3.0"
}
But when I ran npm install(with or without --dev and --dev-all), it only installed connect-assets, no stylus, nib, etc.
How should I do?
It's simply because the npm should not work this way. If I want to install the devDependencies of some depended modules, I have to enter their directories.
One should be aware that npm will not deliver files that are specified in the .npmignore file. This might be the culprit if one was looking to use files in a devDependency that exist in the git repo, but mysteriously are not present in the npm delivery.

Resources