How can I use npm 2.0 on IBM Bluemix? - npm

Is it possible to use npm version 2 on Bluemix? By default it runs version 1.4, but I want to "install" a package from a local directory.

I was able to configure the npm version when using the community open source Node.js buildpack and setting the npm version in my package.json. See below.
"engines": {
"npm": "^2.1.0"
}
cf push mynodeapp -b https://github.com/cloudfoundry/nodejs-buildpack
Not sure if this is possible using the default Node.js buildpack yet.
In the staging output, you should see:
Npm engine: ^2.1.0

Probably you have to modify package.json like below:
"engines": {
"npm": "^2.1.0"
}
After that you can push your app to bluemix and verify the same in staging output.
Hope it helps!!

You could package the dependency inside your application directory, and create a "preinstall" script that will run an npm install on that dependency:
"scripts": {
"start": "node server.js",
"preinstall": "npm install relative/path/to/module"
},
This should work locally and on Bluemix. Note that "postinstall" is also an option.

Related

Dependency miss match error is throwing while npm install if I use `jsonpscriptsrc-webpack-plugin` npm package with gulp 4.0.2

If we try to npm install the jsonpscriptsrc-webpack-plugin npm package along with gulp 4.0.2 to override the jsonpScriptSrc method, we are facing the dependency mismatch issue.
This issue is occurring only if we use the node version 15.0.0 to 15.7.0 and having gulp 4.0.2 in dependency list. For other node versions, it installs the package fine.
package json details
Issue details:
Error details
Replication procedure:
Create a package.json file and copy & paste the below code.
{
"name": "wepack",
"version": "1.1.0",
"license": "SEE LICENSE IN license",
"devDependencies": {
"gulp": "^4.0.2",
"jsonpscriptsrc-webpack-plugin": "^1.0.0"
}
}
Switch the node js version to 15.7.0
Try to npm install inside the package.json file location and you will find the mentioned issue.

Can "NPM -i" (local) install a global package without i know it?

I'm ok with local dependencies that packages install. But now I have a huge concerns about if a local installed package can install other global packages as dependencies.
as example:
npm install nunjucks
npm install sqlite
or
npm install botkit
It is not possible to mark a dependency as global in package.json, so that it is installed system-wide when you run npm i.
Here's an old comment by Isaac Schlueter stating that this will never be implemented.
Hooowever, it would be really simple to write a preinstall script to install arbitary dependencies globally.
{
"name": "Project",
"version": "1.0.0",
"description": "Preinstall script to install global deps",
"main": "index.js",
"scripts": {
"preinstall": "node -e \"const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));\""
},
"dependencies": {
"react": "16.13.1"
},
"globalDependencies": [
"lodash"
],
"license": "ISC"
}
Copy this code into a package.json file in a folder on your PC. Then, in the folder run npm i. It will install React locally (in a node_modules folder) and it will install lodash globally.
You can verify this using: npm i ls -g --depth=0.
Reference: Install dependencies globally and locally using package.json
As to your question:
Can npm -i (local) install a global package without me knowing it?
It's not entirely silent. When running npm i for the above package.json file, you would see the following output:
> Project#1.0.0 preinstall /home/jim/Desktop/Project
> node -e "const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));"
npm WARN Project#1.0.0 No repository field.
audited 6 packages in 1.113s
found 0 vulnerabilities
But whether you would catch this when running npm i on a large project is debatable.

npm install dependencies of local modules

I'm having trouble using npm with a local module. My project's structure looks like:
package.json
local_module/
- package.json
- gulpfile.json
gulpfile.js
The main project's package.json is essentially:
{
"dependencies": {
"local_module": "file:local_module"
},
"devDependencies": {
"gulp": "..."
}
}
The local module's package.json is essentially:
{
"scripts": {
"prepublish": "gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
My intention is keep my project modular by keeping local_module as its own package that is used as a dependency for the main project. I want to run npm install in the main project and use local_module from node_modules. However, local_module needs gulp installed to run the prepublish step, and when running npm install from the main project, it does not install the dependencies for local_module, and so gulp isn't installed, so it can't do the prepublish step.
Several questions like this have been asked, like NPM doesn't install module dependencies, but many are old and there are so many versions of npm that I can't get a clear solution.
How can I get npm to install local_module's dependencies before the prepublish step? I tried adding a preinstall step for the main project, e.g.
"preinstall": "cd local_module && npm install"
But it seems npm tries to run the prepublish step of local_module before running the preinstall for the main project. I want a solution that will do this in one npm install step rather than having a separate step before this to do npm install in the local module.
I have found a solution that will work for me in the immediate future. I changed local_module's package.json to:
{
"scripts": {
"prepublish": "npm install --ignore-scripts && gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
When npm install is run from the main project, the prepublish step is run first in local_module, so I force prepublish to also do an install so that gulp is available to do the actual prepublish step. This is hardly ideal however.

How do I correctly upgrade angular 2 (npm) to the latest version?

Recently I started Angular 2 tutorial at https://angular.io/docs/ts/latest/tutorial/.
and left off with Angular 2 beta 8.
Now I resumed the tutorial and latest beta is beta 14.
If I simply do npm update a few modules (preloaded with the tutorial) are updated but not Angular2 (I can see that with npm ls).
If I do npm update angular 2 or npm update angular2#2.0.0beta.14 it just does nothing either.
The command npm update -D && npm update -S will update all packages inside package.json to their latest version, according to their defined version range. You can read more about it here.
If you want to update Angular from a version prior to 2.0.0-rc.1, then you'll need to manually edit package.json, as Angular was split into several npm modules. Without this, as angular2 package points to 2.0.0-beta.21, you'll never get to use the latest version of Angular.
A list with some of the most common modules that you'll need to get started can be found in the quickstart repository.
Notes:
A cool way to stay up to date with your packages' latest version is to use npm outdated which shows you all outdated packages together with their wanted and latest version.
The reason why we need to chain two commands, npm update -D and npm update -S is to overcome this bug until it's fixed.
Another nice package which I used for migrating form a beta version of Angular2 to Angular2 2.0.0 final is npm-check-updates
It shows the latest available version of all packages specified within your package.json. In contrast to npm outdated it is also capable to edit your package.json, enabling you to do a npm upgrade later.
Install
sudo npm install -g npm-check-updates
Usage
ncufor display
ncu -u for re-writing your package.json
Upgrade to latest Angular 5
Angular Dep packages:
npm install #angular/{animations,common,compiler,core,forms,http,platform-browser,platform-browser-dynamic,router}#latest --save
Other packages that are installed by the angular cli
npm install --save core-js#latest rxjs#latest zone.js#latest
Angular Dev packages:
npm install --save-dev #angular/{compiler-cli,cli,language-service}#latest
Types Dev packages:
npm install --save-dev #types/{jasmine,jasminewd2,node}#latest
Other packages that are installed as dev dev by the angular cli:
npm install --save-dev codelyzer#latest jasmine-core#latest jasmine-spec-reporter#latest karma#latest karma-chrome-launcher#latest karma-cli#latest karma-coverage-istanbul-reporter#latest karma-jasmine#latest karma-jasmine-html-reporter#latest protractor#latest ts-node#latest tslint#latest
Install the latest supported version used by the Angular cli (don't do #latest):
npm install --save-dev typescript#2.4.2
Rename file angular-cli.json to .angular-cli.json and update the content:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"project": {
"name": "project3-example"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
UPDATE:
Starting from CLI v6 you can just run ng update in order to get your dependencies updated automatically to a new version.
With ng update sometimes you might want to add --force flag.
If you do so make sure that the version of typescript you got
installed this way is supported by your current angular version,
otherwise you might need to downgrade the typescript version.
Also checkout this guide Updating your Angular projects
For bash users only
If you are on are on Mac/Linux or running bash on Windows(that wont work in default Windows CMD) you can run that oneliner:
npm install #angular/{animations,common,compiler,core,forms,http,platform-browser,platform-browser-dynamic,router,compiler-cli}#4.4.5 --save
yarn add #angular/{animations,common,compiler,core,forms,http,platform-browser,platform-browser-dynamic,router,compiler-cli}#4.4.5
Just specify version you wan't e.g #4.4.5 or put #latest to get the latest
Check your package.json just to
make sure you are updating all #angular/* packages that you app is relying on
To see exact #angular version in your project run:
npm ls #angular/compiler or yarn list #angular/compiler
To check the latest stable #angular version available on npm run:
npm show #angular/compiler version
Official npm page suggest a structured method to update angular version for both global and local scenarios.
1.First of all, you need to uninstall the current angular from your
system.
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm uninstall -g #angular/cli
2.Clean up the cache
npm cache clean
EDIT
As pointed out by #candidj
npm cache clean is renamed as npm cache verify from npm 5 onwards
3.Install angular globally
npm install -g #angular/cli#latest
4.Local project setup if you have one
rm -rf node_modules
npm install --save-dev #angular/cli#latest
npm install
Please check the same down on the link below:
https://www.npmjs.com/package/#angular/cli#updating-angular-cli
This will solve the problem.
Alternative approach using npm-upgrade:
npm i -g npm-upgrade
Go to your project folder
npm-upgrade check
It will ask you if you wish to upgrade the package, select Yes
That's simple
If you want to install/upgrade all packages to the latest version and you are running windows you can use this in powershell.exe:
foreach($package in #("animations","common","compiler","core","forms","http","platform-browser","platform-browser-dynamic","router")) {
npm install #angular/$package#latest -E
}
If you also use the cli, you can do this:
foreach($package in #('animations','common','compiler','core','forms','http','platform-browser','platform-browser-dynamic','router', 'cli','compiler-cli')){
iex "npm install #angular/$package#latest -E $(If($('cli','compiler-cli').Contains($package)){'-D'})";
}
This will save the packages exact (-E), and the cli packages in devDependencies (-D)
Just start here:
https://update.angular.io
Select the version you're using and it will give you a step by step guide.
I recommend choosing 'Advanced' to see all steps. Complexity is a relative concept - and I don't know whose stupid idea this feature was, but if you select 'Basic' it won't show you all steps needed and you may miss something important that your otherwise 'Basic' application is using.
As of version 6 there is a new Angular CLI command ng update which intelligently goes through your dependencies and performs checks to make sure you're updating the right things :-)
The steps will outline how to use it :-)
npm uninstall --save-dev angular-cli
npm install --save-dev #angular/cli#latest
ng update #angular/cli
ng update #angular/core --force
ng update #angular/material or npm i #angular/cdk#6
#angular/material#6 --save
npm install typescript#'>=2.7.0 <2.8.0'
Best way to do is use the extension(pflannery.vscode-versionlens) in vscode.
this checks for all satisfy and checks for best fit.
i had lot of issues with updating and keeping my app functioining unitll i let verbose lense did the check and then i run
npm i
to install newly suggested dependencies.
If you are looking like me for just updating your project to the latest these is what works form me since Angular 6:
Open the console on your project folder: If you type: ng update then you will get the below message:
We analyzed your package.json, there are some packages to update:
Name Version Command to update
--------------------------------------------------------------------------------
#angular/cli 7.0.7 -> 7.2.2 ng update #angular/cli
#angular/core 7.0.4 -> 7.2.1 ng update #angular/core
There might be additional packages that are outdated.
Run "ng update --all" to try to update all at the same time.
So I usually go straight and do:
ng update --all
Finally you can check your new version:
ng version
Angular CLI: 7.2.2
Node: 8.12.0
OS: win32 x64
Angular: 7.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
#angular-devkit/architect 0.12.2
#angular-devkit/build-angular 0.12.2
#angular-devkit/build-optimizer 0.12.2
#angular-devkit/build-webpack 0.12.2
#angular-devkit/core 7.2.2
#angular-devkit/schematics 7.2.2
#angular/cli 7.2.2
#ngtools/webpack 7.2.2
#schematics/angular 7.2.2
#schematics/update 0.12.2
rxjs 6.3.3
typescript 3.2.4
webpack 4.28.4

npm install bluebird doesn't install module

I am attempting to use bluebird in a node application. I have tried adding bluebird to my package.json, as well as installing via npm install bluebird.
My package.json dependencies:
"dependencies": {
"express": "visionmedia/express",
"mocha": "visionmedia/mocha",
"bluebird": "petkaantonov/bluebird",
"waitjs": "elving/wait"
}
Regardless of what method I try, it doesn't look like the module is actually being installed. After I run the install; in node_modules\bluebird there are only 4 files:
changelog.md
LICENSE
package.json
READEME.md
As you can see, there is no code pulled down which would actually comprise the module. The package.json for bluebird does not have a dependencies section, so I am not sure if maybe the package.json file for the module is incorrect?
I've pasted the package.json contents on pastebin for easier viewing.
I'm pretty stumped why this is not installing correctly.
npm version: 2.11.3.
node version: v0.12.7.
Thanks for any help.
The dependencies section of the packages.json should have version numbers as the module values, not git repos.
If you are having this issue, remove your dependcies section from package.json and then install each module using npm install {module name} -save.
My package.json ended up looking like:
"dependencies": {
"bluebird": "^2.9.34",
"express": "^4.13.1",
"mocha": "^2.2.5",
"waitjs": "^0.2.0"
}
Thanks to untogethered on reddit for the answer.
First thing to always try with module install problems is:
npm cache clean
Then try and install again, also remember to remove the bad install at node_modules/bluebird