NPM not installing packages - node.js

I have a project with dependencies in package.json. When I install with npm install, I get packages installed in ~/.npm but not in the current folder's node_modules.
NPM is creating node_modules, but not installing packages there. There's a .staging folder within node_modules, which contains all of the packages for the projects, but they're not being moved out after retrieval.
Using Node v6.9.1 / npm v3.10.8.
There aren't any other projects/node_modules installed in directories higher than the current one, though there is a package.json in the parent directory as well. No node_modules directory gets created in the parent directory, however.
Strangely enough, when I manually install a package like npm install #angular/core it installs without problem.
This is on Ubuntu 16.04.
package.json:
{
"name": "",
"version": "0.5.0",
"description": "website (Angular2/NodeJS)",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "John Halbert <https://halbert.tech> (john#halbert.tech)",
"license": "SEE LICENSE IN LICENSE.md",
"dependencies": {
"#angular/common": "^2.1.1",
"#angular/compiler": "^2.1.1",
"#angular/core": "^2.1.1",
"#angular/forms": "^2.1.1",
"#angular/http": "^2.1.1",
"#angular/platform-browser": "^2.1.1",
"#angular/platform-browser-dynamic": "^2.1.1",
"#angular/router": "^3.1.1",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"systemjs": "^0.19.39",
"zone.js": "^0.6.26"
},
"devDependencies": {
"concurrently": "^3.1.0",
"typings": "^1.4.0"
}
}

Try to run
echo "" > $(npm config get userconfig)
npm config edit
To see if you have change de node modules default folder, if so, you can reset the configurations by doing
echo "" > $(npm config get globalconfig)
npm config --global edit

After doing more research it looks like this is a memory issue with my server. Running on a low-end VPS with 128Mb RAM.
There are a few suggestions on how to deal with this. I found others suggesting npm config set jobs 1 as a way to limit memory usage, but this hasn't worked for me. Others suggest adding (more) swap, which is disallowed by my hosting provider.
The npm process is actually being killed so it appears this is likely the culprit.

Related

NPM : Error: Cannot find module 'balanced-match'

I just updated the node and npm using nvm. When I start the node server I am getting this error. I tried with different solutions. This type of questions already existed in stack overflow but none of these worked for me. So I tried with these things but no use.
1.Removed node modules and install node modules with npm install.
2.Updated babel-cli version.
3.downgraded node and nvm.
4.npm i balanced-match.
5.npm i -g balanced-match.
6.npm i balanced-match --save.
I am adding my package.json
{
"name": "******",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon express-server.js --exec babel-node",
"build": "babel ./ -d dist",
"serve": "node dist/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"bluebird": "^3.5.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-es6-template-engine": "^2.0.3",
"express-session": "^1.15.6",
"handlebars": "^4.0.11",
"helmet": "^3.13.0",
"html": "^1.0.0",
"instamojo-nodejs": "0.0.5",
"jsonwebtoken": "^8.2.2",
"lodash": "^4.17.10",
"moment": "^2.22.2",
"mongoose": "^5.1.3",
"mongoose-unique-validator": "^2.0.1",
"multer": "^1.3.0",
"mysql": "^2.15.0",
"node-fetch": "^2.1.2",
"node-schedule": "^1.3.0",
"node-xlsx": "^0.12.1",
"nodemailer": "^4.6.8",
"passport": "^0.4.0",
"passport-google-oauth20": "^1.0.0",
"passport-local": "^1.0.0",
"request": "^2.88.0",
"request-ip": "^2.0.2",
"sanitize-html": "^1.18.2",
"utf8": "^3.0.0",
"validator": "^10.2.0",
"xlsx2json": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"nodemon": "^1.17.5"
}
}
In console it showing like this.
console error
I wasted 12 hours time to solve this problem only.
I solved this problem by installing the balanced-match with npm install balanced-match in root folder. I don't know why it is taking root folder node modules. In console error it is clearly given path but I have not aware of it. If anyone explain why it is taking root node modules that would be helpful to me.
I did not see any node packages as balanced-match. Hence, it is giving the error. You can also manually add package in package.json and run npm install.
If you ran this command: npm i balanced-match --save there would be an entry for it in your package.json file. Does your app require this module for production or is it a development tool? That will determine which flag you should pass to the install command. From the docs:
-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.
-D, --save-dev: Package will appear in your devDependencies.
-O, --save-optional: Package will appear in your optionalDependencies.
--no-save: Prevents saving to dependencies.
When using any of the above options to save dependencies to your
package.json, there are two additional, optional flags:
-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator.
-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.
The previous answer does have the most likely fix for your problem. You can either run the install command again with the correct flag for your use case (which will install it and update your package.json), or you can add it manually and run npm install again.
When you install, are there any errors at all? If not, it should work. You can check for installed packages using npm ls (passing optional tags like '-g' will show you all globally installed modules, and you can modify the output by also passing a depth tag like such: --depth=0.

Newbie to NPM and Node.js here and I'm trying to understand global versus local dep installs and how those are shown in package.json

Okay so I'm really more of a designer learning to code. For a project at work I'm helping out with an Angular project so I needed to learn how to use npm and stuff to install Angular CLI and it's deps.
I have an angular project running. It was super easy, no problem. I didn't really edit very much of the package.json, just some of the basics for adding Angular stuff like ng-serve.
When I switched over to our departments actual project, I ran into some pretty big issues getting it to build. Eventually sorted it out, but it kept giving me an error about sass not being able to compile or something to that extent.
Then I moved back over to my practice project. I copy and pasted it into a sub directory of our full project so that I could begin the process of pulling over components that I had made over to the main project. When I tried to run it again, it didn't run! It gave me a whole bunch of errors basically saying that I didn't have node-sass installed. Which I thought I did. It's listed in the dependencies section of the package.json and even after hitting "npm install" a couple of times it was still giving me node-sass errors. When I went back to the original folder that I had copied practice project from it also failed to run even though I'd not changed that file at all.
So then I thought... maybe I removed node-sass as a global install? I remember when I was looking up webpack tutorials after starting my Angular practice project, reading that it's best to do as few global installs as possible because you want each project to have it's own specific version of the dep before you upgrade them etc.
And I remember looking up my global install deps and then looking up how to uninstall one, but I don't remember if I did that for node-sass or not.
Anyway, once I run node-sass install globally on the other project it also starts working no problem.
TL;DR
Do npm depencies install locally?
If they are listed but there is no local or global install, shouldn't npm install install it? Or does it not?
If it does, then how come I have node-sass listed as a dep in the package.json file and running npm install didn't fix it?
Here's my package.json for reference:
{
"name": "spanner-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.3",
"#angular/common": "^6.0.3",
"#angular/compiler": "^6.0.3",
"#angular/core": "^6.0.3",
"#angular/forms": "^6.0.3",
"#angular/http": "^6.0.3",
"#angular/platform-browser": "^6.0.3",
"#angular/platform-browser-dynamic": "^6.0.3",
"#angular/router": "^6.0.3",
"core-js": "^2.5.4",
"node-sass": "^4.9.0",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "^6.0.3",
"#angular-devkit/build-angular": "~0.6.6",
"typescript": "~2.7.2",
"#angular/cli": "~6.0.7",
"#angular/language-service": "^6.0.3",
"#types/jasmine": "~2.8.6",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
Thoughts?
dependencies listed in package.json will be installed locally (for the project only) when running npm install. These dependencies will be installed in the node_modules folder by default.
You can check if node-sass is installed for the project by looking for the node-sass folder in node_modules. node-sass will be installed locally by npm install even though it is also installed globally.
You're right that you should have as few packages installed globally as possible, and having a dependency installed globally should only be a last resort temporary solution to your problem. In your situation I would do the following:
Remove node-sass from package.json
Uninstall node-sass globally: npm uninstall -g node-sass
Check if the node_modules/node-sass folder exists
If it does, delete it
Re-install it by npm install --save node-sass
Verify that the issue is fixed
If it's still not working: delete the entire node_modules folder, then run npm install again

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.

Angular 2 UNMET PEER Dependency Error on Windows 10

I am trying to run my web application on a Windows 10 Machine with the package.json (given below). I have Node version 5.6.0 and Npm version 3.6.0. But unfortunately it's always throwing an UNMET Peer Dependency Error and the following files of the AngularLoader Hierarchy fails to load when I run my project(powered by Laravel PHP): shim.js, zone.js, reflect.js, system.js. Contrary the same config runs absolutely smooth on a Linux Dev Machine. Any sort of help for installing the same on the Windows Machine will be highly appreciated as I am quite new to the Angular 2 Domain.
I have already tried the following:
rm -rf node_modules/
npm cache clean
npm install
And also installing like npm install angular/core angular/common angular-forms
P:S: Upgrading to Angular 4 is not an option. Sorry!!!
Here is my package.json:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"bootstrap-sass": "^3.3.7",
"gulp": "^3.9.1",
"jquery": "^3.1.0",
"laravel-elixir": "^6.0.0-11",
"laravel-elixir-vue-2": "^0.2.0",
"laravel-elixir-webpack-official": "^1.0.2",
"lodash": "^4.16.2",
"vue": "^2.0.1",
"vue-resource": "^1.0.3"
},
"dependencies": {
"#angular/common": "^2.1.2",
"#angular/core": "^2.1.2",
"#angular/forms": "^2.1.2",
"#ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.11",
"#types/jquery": "^2.0.41",
"jquery": "^3.2.1",
"ng2-ui": "^0.11.5",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.26"
}
}
Here is the full install log of the Windows Machine:`
Link to Error Doc
If you use libraries that depend on Angular 4 you can expect these errors.
Take ng-bootstrap 1.0.0-alpha.25 for example; If you check the CHANGELOG.md file;
BREAKING CHANGES
ng-bootstrap requires a minimal version of Angular 4.0.3
So why does this happen? Short answer; you should get rid of the version tags ^and ~ as this is your problem to begin with:
"^1.0.0-alpha.11" allows for versions >= 1.0.0-alpha.11 < 2.0.0
use "#ng-bootstrap/ng-bootstrap": "1.0.0-alpha.11" instead.
I suggest you read up on npm semver
Some might say you do not have to drop it completely but I've had my fair share of issues. Not all developers understand semantic versioning it seems. Also, it's a very bad idea to use these wildcards with alpha and beta packages as they come with breaking changes by default it seems.
How to fix it from here?
You say you have a Linux Dev Machine where you can build this app without any issues. Try doing an npm shrinkwrap on that machine. This will write an npm-shrinkwrap.json file with all used library versions at that time. Then, when doing an npm install on the Windows 10 machine, this file will be checked to see what versions should be downloaded instead.

Build:Cannot find type definition file for 'node'

VS 2015 community edition (at home), npm 3.10, Angular 2
Im trying to pull get Angular2 setup within an ASP.Net MVC 5 app. The template I started with used an older version of Angular, so I updated the package references.
When I build, the first error in the list is:
Build:Cannot find type definition file for 'node'
There are dozens of other errors after that but Im assuming most are due to this first issue.
Here is the package.json and typings.json
package.json
{
"version": "1.0.0",
"name": "aspnet",
"private": true,
"scripts": {
"postinstall": "typings install",
"typings": "typings"
},
"dependencies": {
"#angular/common": "~4.0.0",
"#angular/compiler": "~4.0.0",
"#angular/core": "~4.0.0",
"#angular/forms": "~4.0.0",
"#angular/http": "~4.0.0",
"#angular/platform-browser": "~4.0.0",
"#angular/platform-browser-dynamic": "~4.0.0",
"#angular/router": "~4.0.0",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.8.4",
"bootstrap": "^3.3.7"
},
"devDependencies": {
"#types/core-js": "^0.9.41",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.1",
"gulp-tsc": "^1.3.1",
"gulp-typescript": "^3.1.6",
"path": "^0.12.7",
"typescript": "~2.1.0",
"typings": "~2.1.1"
}
}
typings.json
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
}
}
If I try to update just the typings, I get these messages
*typings WARN deprecated 11/21/2016: "registry:dt/node#6.0.0+20160909174046" is deprecated (updated, replaced or removed)
typings WARN deprecated 9/14/2016: "registry:dt/core-js#0.0.0+20160725163759" is deprecated (updated, replaced or removed)
typings WARN deprecated 10/25/2016: "registry:dt/jasmine#2.2.0+20160621224255" is deprecated (updated, replaced or removed)*
[ update ]
cleaning out my node_modules folder, then running npm install again cleared things up. This seems to happen most often when I move a project folder to another location on my system.
In my case, I solved my problem. Hopefully it helps some else later.
npm install #types/node --save-dev
I had several problems updating packages through visual studio. From now i always update or add packages with the powershell console.
Start PowerShell and navigate to the folder where package.json is located and then run npm install Restart visual studio after the installation is done.
You can also try to delete your node_modules folder then run npm install
Hope this will solve your problems.
Restarting or reloading my VSCode worked
For local Visual Studio
If you're starting with a clean template the build in VS functionality should probably work!
Go to Dependencies > npm > Right Click > Restore Packages
Then try build again.
For Visual Studio Team Services
Install node https://nodejs.org/en/download/
Restart your agent service (VSTS Agent) if not using hosted agents
Add a build task to run npm install
Click the menu icon next to 'Working folder' to choose the location where your project.json file is located.
sometimes its just because some package(s) are missing. you can try running yarn install or npm install should resolve.
The easiest way to go around this in vscode is.
create a .vscode directory, then inside it, create settings.json and put the below json and you are good to go.
{
"search.exclude": {
"**/node_modules": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"env-*": true
},
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": true,
"env*": true
}
}
Problem can be around other issues as well
Try one of the step of the solution posted here Cannot find type definition file for 'node' by me
I had this problem when i've been working with RN and i put a incorrect dependency on my package.
"#types/": "react-navigation/native",
react-navigation/native don't exists
json
When i tried run tsc with it, i got this
Restart Typescript or re-open vscode worked for me

Resources