NPM doesn't install dependencies that need build - node.js

My package.json file looks like the following :
{
"name": "anna-backend",
"version": "1.0.3",
"description": "Backend for ANNA intranet",
"main": "app.js",
"author": "IpsaOne DevTeam",
"private": true,
"license": "ISC",
"dependencies": {
"async": "^2.6.0",
"bcrypt": "^1.0.3",
"body-parser": "^1.17.2",
"mmmagic": "^0.4.6",
[...]
}
}
When I run npm install in the folder, everything installs well except the dependencies that require building via node-gyp (like bcrypt, mmmagic) and I have to install them manually by typing npm install mmmagic. Otherwise, they're just not installed and my application doesn't start.
Is it expected behaviour ? Can I do anything about it ?

mmmagic module has issues on install
https://github.com/mscdex/mmmagic/issues/111
try install at last version 0.5.0

Related

Why do npm packages resolve from /AppData and not from local /node_modules?

When developing locally in VS Code, packages are resolving to C:/Users/<User>/AppData/Local/Microsoft/TypeScript/3.5/node_modules/#types/<package>/index and not from the /node_modules directory local to the package.json.
I'm not getting any compiling errors or when deploying, but I can't wrap my head around why it's not resolving to the location I'd expect it to. Any idea why and how to fix it?
I'm using Node 8.12 and NPM 6.4.1.
Here's an example
package.json
{
"name": "superapp",
"version": "0.0.1",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server"
},
"keywords": [],
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.0.0",
"express": "^4.17.1"
}
}
Your module in question #types/express is not present in package.json
npm install #types/express --save-dev
You may have installed it globally previously and that is why it can be found in AppData as a backup solution for the compiler

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.

npm install does not install the dependencies of individual node modules into the respective node modules folders

npm install was installing node modules correctly until recently when I ran into a bug. Now, npm install does not install the dependencies of individual node modules into the respective node modules folders.
See screenshot for what I mean.
The finder window at the forefront shows the correct npm install before the bug. npm install express would download and put the files in correct folders. The accepts folder is a node module of express and has its own node modules, mime types and negotiator.
Now, the accepts folder and its own node modules sit out at the same level as express folder. As seen in the finder window in the back.
This is causing me not to be able to upload to heroku.
Please advise on how to fix.
Here's my package.json
{
"name": "node-muse-examples-webgui",
"version": "0.1.0",
"description": "An example on how to use the node-muse module in a web interface.",
"main": "index.js",
"engines": {
"node": "7.2.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/ShaPOC/node-muse/tree/master/examples/webgui"
},
"author": "Jimmy Aupperlee <j.aup.gt#gmail.com>",
"license": "GPLv3",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"leapjs": "^0.6.4",
"mongodb": "^2.2.7",
"node-muse": "^0.1.0",
"socket.io": "^1.3.5"
}
}
That behavior is not a bug, it actually is a new behavior introduced with npm#3.
That normally should not cause any conflict or problems, but if it does in your case try to install it with
npm install --legacy-bundling
instead, so delete the whole node_modules folder and reinstall it with that command.

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 install is not installing grunt js from dependencies

I am trying to automatic all the package installations automatic for developers. So I have both package.json and grunt file in the same directory. I want to do npm install first so that all dependencies will be installed and when developer executes grunt on command line things will be ready. May I know why it is not working. The other thing is may I know the difference between dependency and devdependencies.
{
"name": "TestProject",
"version": "0.1.0",
"description": "this project is for test",
"main": "index.js",
"dependencies": {
"grunt": "~0.4.2",
"grunt-contrib-uglify": "~0.2.7",
"uglify-js": "~2.4.3",
"grunt-contrib-watch":"~0.5.3",
"grunt-contrib-jshint": "~0.7.2",
"qunit": "~1.11.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"qunit": "~1.11.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-watch":"~0.5.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}
You are probably missing the command-line utility for Grunt.
That can be installed in your shell, using
npm install -g grunt-cli
The CLI is distributed independently from the grunt package or the grunt- plugins. You should include instructions to install grunt-cli globally in the same dev environment setup documentation where you indicate how to set up node, npm, bower, or the like.
Update
If you are so adamant about installing grunt-cli on npm install, I guess one option might be using npm scripts.
Include in your package.json (note: untested)
{
"postinstall": "npm i -g grunt-cli"
}
I'd discourage this, though. Just install them by hand.

Resources