NPM installs older version & doesn't fully installs recursive dependencies - json

In a project I inherited, the packages.json looks roughly like this:
{
"name": "...",
"version": "...",
"description": "",
"author": "...",
"license": "ISC",
"dependencies": {
"lodash": "^3.10.1",
"assemble": "^0.4.37",
"cheerio": "^0.16.0",
"grunt": "^0.4.4",
"grunt-build-control": "^0.1.3",
},
"keywords": [
"handlebars-helper-md",
"handlebars-helper-rel"
]
}
When I first got it, lodash was ~2.4.1 and I'm trying to update it to 3.10.1 (as shown above). However, npm continues to install 2.4.1 at the top-level (Despite the package.json requesting the newer version) and it does not install the requested versions 2.4.1 or 2.4.2 in some of the dependencies (like assemble and cheerio). Thus when I npm install lodash#3.10.1 it complains about unmet dependencies.
I've tried removing node_modules and npm clear cache and rm -rf $HOME/.npm in different orders and combinations with no change.
How do I get lodash#3.10.1 to install at the top-level and the requested version of lodash in all the dependencies (and not have the dependencies use the top-level copy of lodash -- which I thought was the normal way for npm to work)?
Preferably a solution would not require updating all the dependencies to new versions (assuming that is even possible). That could be a solution, but that would require a lot more validation to make sure nothing broke.

Related

How to get the polymer-cli (1.0.0) to use the latest version of polymer (2.0.0)

I just updated the polymer cli, on my linux pc to the freshly released version 1.0.0 (as confirmed by the polymer --version command).
However when I use the cli to set up a new polymer-2-application project, the bower.json file is still pointing to the 2.0.0-rc.3 version of polymer and other pre 2.0 release candidate dependencies.
{
"name": "temp",
"main": "index.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0-rc.3"
},
"devDependencies": {
"web-component-tester": "^6.0.0-prerelease.5",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0-rc.7"
}
}
How can I get polymer-cli to use the newly released stable 2.0.0 version?
I don't believe you are actually looking for the polymer-cli update. The polymer-cli is ran from a terminal and has commands for building, linting, serving, etc. The current version of the CLI is 1.0.0 as of today.
To update the CLI use, npm i -g polymer-cli
I believe what you are really asking about is the Polymer library which was tagged the other day as stable 2.0.0. you can update the line in your bower.json to point to ^2.0.0 instead of ^2.0.0-rc.3. Take a look at the Polymer Starter Kit for other dependency updates you should probably make. https://github.com/PolymerElements/polymer-starter-kit/blob/2.0-preview/bower.json
If you don't feel like taking a look...
{
"name": "temp",
"main": "index.html",
"dependencies": {
"polymer": "Polymer/polymer#^2.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
},
"devDependencies": {
"web-component-tester": "^6.0.0"
}
}
https://www.polymer-project.org/2.0/docs/upgrade
You'll need to run npm install -g polymer-cli#next instead of the regular polymer-cli.
More information can be found here: https://www.polymer-project.org/2.0/docs/upgrade

How to Automate version number in package.json with Jenkins

Here is my package.json looks like:
{
"name": "Myproject",
"version": "0.4.13",
Note:Here 4 is not the minor version.0013 is minor
"dependencies": {
"lodash": "^4.0.0",
"vinyl-fs": "2.2.1"
},
"repository": {},
"devDependencies": {
.........
......
How can I automate versioning of package.json using Jenkins build.
Required format should be:
0.4.13-$BUILD_NUMBER
So far I try to do it using sed command:
sed -i "s/version: .*/version: 0.4.13-$BUILD_NUMBER/" package.json
But it's not updating version number in package.json file.
Also used
npm version 0.4.13-$BUILD_NUMBER
FYI:The generated build artifact should look like 0.0013-1.war
If you're using grunt, you could use the recommendation here.
Alternatively, there's a built in function in npm that does this for you. Run npm version, docs here.

Heroku does not read node version

I have a Node project that I want to host on Heroku. I have explicitly defined node and npm versions in my package.json (located in the root directory), which looks like this:
{
"name": "*********",
"version": "0.0.0",
"private": true,
"engines": {
"node": "0.12.x",
"npm": "2.5.x"
},
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.13.3",
...
}
However, when I try to push the app to heroku
git push heroku master
Heroku tries to build the app, but it seems like it's not able to read the node and npm versions. Here is the response I get.
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version (latest stable) via semver.io...
remote: Downloading and installing node 4.2.1...
remote: Using default npm version: 2.14.7
Why does heroku not read the node and npm version from package.json?
#rdegges was right that the package.json wasn't correctly committed to Heroku. So just following the Heroku instructions didn't work for me for some reason. Here is what I had to do in order to make it work.
git clone <my git project>
heroku create <app name>
#remove package.json
mv package.json tmp_package.json
git add package.json
git commit -m "removed package.json"
#re-add package.json
mv tmp_package.json package.json
git add package.json
git commit -m "re-added package.json"
git push heroku master
This works for me -- make sure you've actually committed these changes to Git, and pushed the repository to Heroku. You may also want to specify exact Node and NPM release numbers for your Heroku app.
While this WILL WORK with the variable releases you've got specified, it's not recommended, as small changes in releases might cause issues for you.
For reference, here are the Heroku docs on specifying a Node.js runtime as well: https://devcenter.heroku.com/articles/nodejs-support#node-js-runtimes
I added the version to the package.json as others mentioned and it worked for me. These versions were referenced from the defaults that Heroku uses during the build if none are specified:
"engines": {
"node": "14.18.3",
"npm": "6.14.15"
},
Also, I'd recommend adding this setting to your app via the CLI for more output, which really helps:
heroku config:set NPM_CONFIG_LOGLEVEL=verbose --app=<your_app_name>
👍🏼
In an easy way
1- check your node version, let say it is like this: "node": "17.3.0"
2- Go inside the the package.json, at the very top below name and version add this
"engines": {
"node": "17.3.0",}
3- Delete package-lock.json then reinstall it by npm install.
After 3 hours working this mechanism helped me, I wanted to share with you all :) I hope it works for you too
Maybe your master branch is not the branch is not updated, try merging the branch that you want to deploy into master in order to use:
git push heroku master
Don't give 'x' on the version
"node": "0.12.x",
"npm": "2.5.x"
write complete version.
Ex.
"node": "0.12.0",
"npm": "2.5.0"
I tried the other solutions, but it didn't work for me. However, by changing the name field in package.json, it worked:
From:
{
...
"name": "foo"
...
}
To:
{
...
"name": "bar"
...
}
Alternative 2:
When I had to do the same on my other computer, it didn't work, but I tried removing package.json, recreating it from scratch, and then it worked for some odd reason (file metadata?):
$ rm package.json
$ npm init
Make sure the lockfile is up to date
In order to update the package-lock.json, run npm install and check in the changes to the file to git.
Then, git add . && git commit -m "update pkg-lock" && git push heroku master
I added the node version to package.json, but it would only accept it in the format
<major version>.x
i.e.
"name": "myapp",
"version": "1.0.0",
"engine": {
"node": "16.x"
}
I got that info from the heroku docs here - no other way of specifying it worked except that 16.x.
In my case the issue was with package.json, it was missed up due to some manual changes, so reverting to old version of repo solved my issue.

Bower error: ENOTFOUND Package bower-bootstrap-accordion not found

I am trying to install this plug in which is the Angular UI Bootstrap, I do not need the full library, only that plug in, and I am getting the error:
the command I am entering in the terminal:
bower install bower-bootstrap-accordion --save
and then the error:
Bower error: ENOTFOUND Package bower-bootstrap-accordion not found
here is the bower.json
{
"name": "bower-bootstrap-accordion",
"license": "MIT",
"version": "0.11.0",
"author": {
"name": "https://github.com/angular-ui/bootstrap/graphs/contributors"
},
"dependencies": {
"bower-bootstrap-collapse": "0.11.0"
},
"main": "ui-accordion-tpls.js"
}
Link to the plugin
do I have to install the full library ?
bower-bootstrap-accordion is not registered in the Bower registry and therefore the Bower client cannot find it by name.
You can use the Git repository URL when defining the dependency. This will save the Bower client the need to search for the package URL in the Bower registry.
"dependencies": {
"bower-bootstrap-accordion" : "git://github.com/ui-bootstrap-bower-test/bower-bootstrap-accordion.git"
}
In addition this package has dependencies on additional packages such as bower-bootstrap-collapse, bower-bootstrap-transition which are also not registered in the Bower registry. You will have to include it in the same way in your dependencies.
I think all those packages are from the same author - https://github.com/ui-bootstrap-bower-test/

What is the recommended manifest JSON format for Bower packages?

Using the $ bower init command, I have created a bower.json for my package and registered it with Bower, no problem.
After looking at the Github homepages for some popular Bower packages, e.g. RequireJS and Modernizr, I've noticed their repo's don't contain a bower.json or a component.json. How is this possible?
I've also noticed that when I download any Bower package, the package contains a .bower.json file (note the dot in the beginning) and that file contains quite a bit more information than what I was asked during $ bower init for my package. For example, below is the .bower.json from Modernizr:
{
"name": "modernizr",
"homepage": "https://github.com/Modernizr/Modernizr",
"version": "2.6.2",
"_release": "2.6.2",
"_resolution": {
"type": "version",
"tag": "v2.6.2",
"commit": "ca45d02757b83367d8455d477e3cbc42dfdee035"
},
"_source": "git://github.com/Modernizr/Modernizr.git",
"_target": "~2.6.2",
"_direct": true
}
When I download my newly created package, it just contains the same info that I originally checked in to git.
Is there a new format for bower.json that I should be using? Or did I simply miss something in the setup process?
Bower doesn't need a bower.json or a component.json to install packages. The manifest file provide some useful info, like dependencies, ignored files, version and etc, but in the end it just downloads Git commits and place them somewhere.
In the case of Modernizr/Require.js, someone just registered their repos and Bower is retrieving a tag.
About the .bower.json file: this is generated by Bower itself after installing a package. It contains some more verbose info about a package, like the commit from which the package was retrieved, for example.
TL;DR: Keep using bower init, it'll do the right thing for you!
I am using Yeoman and the following is the content of my bower.json file. I thought it might help you. (I have installed all the latest versions of bower and grunt)
{
"name": "yowebapp",
"version": "0.0.0",
"dependencies": {
"sass-bootstrap": "~3.0",
"requirejs": "~2.1.4",
"modernizr": "~2.6.2",
"jquery": "~1.9.1",
"d3":"~3.3.2",
"angular":"1.0.7"
},
"devDependencies": {}
}
and I download my dependencies with bower install.