npm doesn't install devDependencies recursively - node.js

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.

Related

Only install packages that are included in the package.json

I just want to install only packages that are included in the packages.json. But when I run npm install, over 800 packages are suddenly installed. Is there a specific command to realize this or is my package.json (see below) wrong?
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "test",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.13.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^5.0.0",
"gulp-concat": "^2.6.0",
"gulp-cssnano": "^2.1.2",
"gulp-htmlmin": "^4.0.0",
"gulp-imagemin": "^4.1.0",
"gulp-install": "^1.1.0",
"gulp-jade": "^1.1.0",
"gulp-jsonminify": "^1.0.0",
"gulp-ng-annotate": "^2.0.0",
"gulp-sass": "^4.0.1",
"gulp-uglify": "^3.0.0"
},
"dependencies": {
"critical": "^1.2.2",
"imagemin-pngquant": "^5.0.0"
}
}
npm install uses package.json to install packages you want AND their own dependencies. So you haven't choice unless you want broken packages ? In that case you could manually uninstall packages you don't want.
In this case when u install this packages the dependencies of that particular packages has also been installed.
Like if u install critical module then =>
bluebird
chalk
cheerio
clean-css
cli
debug
filter-css
fs-extra ... etc
has also been installed, that's the case in here
I am not sure why would that be happening, whenever we run npm install it picks up the package.json and installs packages defined in it including the transitive dependencies. By looking at your package.json there should not be 800 of them.unless you have multiple package.json linked up with each other.
I would recommend to copy package.json to a different directory and clear cached in modules and
run npm install --log-level=verbose
this should give in the details for the rest packages being called up.

how to download and install all node modules through package.json?

I want to invoke and download all node modules through maven, in maven I have defined the plugins to install it but now in my package.json i have defined the following npm install command, please advise how can i install all node modules and can define them in package.json
package.json
{
"name": "MyProject",
"version": "1.0.0",
"author": "Saral",
"scripts":{
"start":"node gulpfile.js",
"prebuild": "npm install",
"build": "gulp"
},
"dependencies": {
"gulp": "*",
"gulp-ruby-sass": "*",
"gulp-util": "*",
"gulp-rename": "*",
"gulp-concat": "^2.6.0",
"gulp-concat-vendor": "0.0.4",
"map-stream": "*",
"gulp-livereload": "*",
"gulp-concat": "*",
"gulp-uglify": "*",
"gulp-minify-css" : "^1.2.1",
"gulp-notify":"2.2.0",
"gulp-inject": "1.5.0",
"run-sequence": "1.1.4",
"stream-series": "0.1.1",
"gulp-gzip": "1.2.0",
"gulp-clone": "1.0.0",
"gulp-watch": "*"
}
}
Go to your terminal and type in
npm install
This will crawl through all the required packages mentioned in package.json and download it to node_modules folder.
When using gulp in your gulpfile.js
var install = require("gulp-install");
gulp.src(['./bower.json', './package.json'])
.pipe(install());
So when you run gulp in your terminal all the packages in bower.json and package.json will be downloaded into bower_components and node_modules, respectively.
As I understand the question, just use the "Frontend Maven Plugin"
It installs node & npm: https://github.com/eirslett/frontend-maven-plugin#installing-node-and-npm
Executes npm install, which is already the default argument and can be omitted: https://github.com/eirslett/frontend-maven-plugin#running-npm

NPM CLI install/update single git dependency

I have a package.json with a lot of dependencies. It can look something like that (I omitted the other keys):
{
"dependencies": {
"body-parser": "git+ssh://git#github.com:arik-so/someRepository.git",
"bs58check": "1.0.5",
"canonical-json": "0.0.4",
"compression": "1.4.0",
"cookie-parser": "1.3.1",
"cookie-session": "^1.1.0",
"csv": "0.4.2",
"zpad": "0.5.0"
}
}
Now, what I am trying to do is the following: I would like to use the CLI to only update the body-parser dependency. I am fine with reinstalling it, doing whatever needs to be done. I just do not want to have to do the full package installation because it takes too long. How would I go about doing that?
npm install --save 'git+ssh://git#github.com:arik-so/someRepository.git#master' will install the latest version of this package

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.

NPM not creating .bin directory

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

Resources