Node.js shrinkwrapped package.json causes npm install to update new versions regardless - node.js

I've got a npm-shrinkwrap.json and a package.json in a git branch called "deployment".
On my servers, I fetch and merge this deployment branch from github. This ensures that my servers have the latest deployment version.
Because the node_modules binaries etc. are not being shipped, I need to run npm install or npm update on the server side too, after the project repository has been pulled from the server.
This is why I decided to use npm shrinkwrap. However, even when I have this npm-shrinkwrap.json in the main folder and run npm install, it still installs newer versions of submodules, even though the shrinkwrapped json file has locked these down. It seems like npm does not even look at the shrinkwrap file.
Could anyone explain why this happens, and how to resolve this situation?
This is part of package.json:
"dependencies" : {
"eventemitter2" : "0.4.9",
"after" : "0.4.1",
"express" : "2.5.9"
},
"devDependencies" : {
"mocha" : ">= 1.0.3 < 2",
"should" : ">= 0.6.3 < 1",
"request" : ">= 2.9.202 < 3",
"commander" : ">= 0.6.0 < 1"
},
Whereas npm-shrinkwrap.json is:
{
"name": "appname",
"version": "0.0.1",
"dependencies": {
"eventemitter2": {
"version": "0.4.9"
},
"after": {
"version": "0.4.1"
},
"express": {
"version": "2.5.9",
"dependencies": {
"connect": {
"version": "1.8.7",
"dependencies": {
"formidable": {
"version": "1.0.9"
}
}
},
"mime": {
"version": "1.2.4"
},
"qs": {
"version": "0.4.2"
},
"mkdirp": {
"version": "0.3.0"
}
}
},
"commander": {
"version": "0.6.0"
},
"should": {
"version": "0.6.3"
},
"request": {
"version": "2.9.202"
}
}
}
Yet, when I ran npm install it updated qs from version 0.4.2 to version 0.5.0. Also, it updated mime to 1.2.5. Why did it do this?
The npm install returned this:
qs#0.5.0 ./node_modules/express/node_modules/connect/node_modules/qs
mime#1.2.5 ./node_modules/express/node_modules/connect/node_modules/mime
Interestingly enough the shrinkwrap contains neither of these. I guess this is the problem. Now the question is why it did not contain these.

Your npm-shrinkwrap.json doesn't include connect's version of qs. You should npm install before you generate your shrinkwrap.

Related

Google app scripts autocompletion in vs codium not working

I'm trying to run GAS in vs codium using node.js, npm and clasp.
Everything is synced correctly but the autocompletion is not working (it worked before but no more)
when I look in the directories, I see this in package.json:
"dependencies": {
"#types/google-apps-script": "^1.0.56"
}
and this in package-lock.json:
"dependencies": {
"#types/google-apps-script": "^1.0.56"
}
},
"node_modules/#types/google-apps-script": {
"version": "1.0.56",
"resolved": "https://registry.npmjs.org/#types/google-apps-script/-/google-apps-script-1.0.56.tgz",
"integrity": "sha512-3YGOtRlnWPSARl/n2BKt0qiIA6Y3/5BLC2zH9s/jcu+1rpxR07noLCFxTZ2BQBIfDl6+Vs9iKjLTgdbbL8q/mg=="
}
},
"dependencies": {
"#types/google-apps-script": {
"version": "1.0.56",
"resolved": "https://registry.npmjs.org/#types/google-apps-script/-/google-apps-script-1.0.56.tgz",
"integrity": "sha512-3YGOtRlnWPSARl/n2BKt0qiIA6Y3/5BLC2zH9s/jcu+1rpxR07noLCFxTZ2BQBIfDl6+Vs9iKjLTgdbbL8q/mg=="
}
}
I'm not familiar with node nor npm, is there a possible conflict ? I see two package.json files, one in the main directory and one in nodes_modules#types\google-apps-script, and package-lock.json is also in the main directory and in node_modules.

Creating a Node NPM module in 9.2.0 to support older versions of Node

Now that Node 9.2.0 has all the new features of the language, how do I go about creating a node module that is backwards compatible with older versions?
If I have a small module that Node 9 supports out of the box, like this.
const {map} = require('lodash')
async function test (...args) {
return map(args, (item) => {
return `${item} yeah`
})
}
module.exports = test
Are there any was to use babel to transpile this for the specific backward version that I would need to support using babel env? Is there any way I can conditionally load those babel development dependencies, say installing this via Node 4 using post-install scripts?
It seems like this is one solution one downside of which is it requires babel-runtime as a dep just in case, even if the current version of node doesn't need it. But in 9.2.0 the code above is the built code, it's simply moved by babel.
Here's an example package.json and on install it will build the src.
{
"name": "example",
"version": "1.0.0",
"main": "lib/index.js",
"scripts": {
"build": "babel src -d lib",
"postinstall": "npm run build"
},
"dependencies": {
"babel-runtime": "^6.26.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1"
},
"babel": {
"plugins": [
"transform-runtime"
],
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
}

unexpected token import in ES2017 with babel and Jest

I try to use Jest with bablejs and ES2017 in my project, according to the Jest Getting Started page and also Bablejs config for ES2017 this is my .babelrc file :
{
"presets": ["es2017"],
"env": {
"test": {
"presets": ["es2017"]
}
}
}
And my package.json is:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2017": "^6.24.1",
"jest": "^21.2.1"
}
}
When I type npm test to run all my test with jest i get these error :
){import StateList from './StateList';
^^^^^^
SyntaxError: Unexpected token import
It means it doesn't know import.
babel-preset-es2017 does not transform import statements, because it only includes the plugins: syntax-trailing-function-commas and
transform-async-to-generator.
When installing babel-preset-es2017 you also get a warning that it has been deprecated in favour of babel-preset-env, which contains everything that the es201x presets contained and more.
warning babel-preset-es2017#6.24.1: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
As shown in the Migration guide from es2015 to env, it is a drop-in replacement.
npm install --save-dev babel-preset-env
And change your .babelrc to:
{
"presets": ["env"]
}
Do not confuse babel-preset-env with Babel's env option, which I have removed from your current config, since you are using the exact same presets for the test environment as for any other, so it doesn't have any effect.
You can configure babel-preset-env to only transform features that are not supported by the platform you target, for example { "targets": { "node": "current" } } will only transform features that aren't supported by the Node version you are running. If no targets are specified, it will transform everything. For details see the Env preset documentation.
Note: With the upcoming version 7 of Babel, the official packages will be published under the namespace #babel, which means that babel-preset-env will be #babel/preset-env.

How to tell bower to get the latest version of all packages ignoring semantic versioning

This is how my bower.json file looks like:
{
"name": "myproject",
"version": "0.0.1",
"private": true,
"author": "Tom",
"dependencies": {
"requirejs": "~2.1.10",
"requirejs-domready": "~2.0.1",
"ac-core": "git+http://ac-src/ac/bower-ac-core.git#^0.14.1",
"ac-grid": "git+http://ac-src/ac/bower-ac-grid.git#^0.13.1",
"ac-sparkline": "git+http://ac-src/ac/bower-ac-sparkline.git#^0.6.1",
"ac-highcharts": "git+http://ac-src/ac/bower-ac-highcharts.git#^0.3.2",
"ac-ilist": "git+http://ac-src/ac/bower-ac-ilist.git#^0.4.1",
"ac-tree": "git+http://ac-src/ac/bower-ac-tree.git#^0.1.1",
"ac-legacy": "git+http://ac-src/ac/bower-ac-legacy.git",
"lodash": "~2.4.1",
"angular-toastr": "0.4.0"
},
"devDependencies": {}
}
This file was created 1 year ago. After that several changes were made to all the modules we are using and major versions of all the modules are changed now.
Because of Semantic Versioning, I am not allowed to update packages to their latest available version.
How can I force bower to update all the packages to its respective latest available version?
How can I also update bower.json file so that the next person trying to update the bower packages does not face the same issue.
Removing SemVer helped. This is how the bower.json file looks now:
{
"name": "myproject",
"version": "0.0.1",
"private": true,
"author": "Tom",
"dependencies": {
"requirejs": "~2.1.10",
"requirejs-domready": "~2.0.1",
"ac-core": "git+http://ac-src/ac/bower-ac-core.git",
"ac-grid": "git+http://ac-src/ac/bower-ac-grid.git",
"ac-sparkline": "git+http://ac-src/ac/bower-ac-sparkline.git",
"ac-highcharts": "git+http://ac-src/ac/bower-ac-highcharts.git",
"ac-ilist": "git+http://ac-src/ac/bower-ac-ilist.git",
"ac-tree": "git+http://ac-src/ac/bower-ac-tree.git",
"ac-legacy": "git+http://ac-src/ac/bower-ac-legacy.git",
"lodash": "~2.4.1",
"angular-toastr": "0.4.0"
},
"devDependencies": {}
}

My custom NPM Package is not found

Got very strange issues. Basically i decided create my own npm package, and publish it to the world. During development, I was testing it as s simple node module, and was able to use it using next code:
var r = require('./lib/%mymodulename%');
Of course it was in the lib folder.
Now, I organised it as a npm package, and my package.json looks next:
{
"name": "mymodulename",
"author": "xxx",
"description": "xxx",
"version": "0.0.1",
"homepage": "xxx",
"repository": {
"type": "git",
"url": "xxx"
},
"main": "/lib/mymodulename.js",
"scripts": {
"install":"node install.js"
},
"dependencies": {},
"engines": {
"node": ">=0.9"
}
}
when i am trying to test it via : npm install . -g it is installed successfully and i am able to see my local module via:
npm ls -g
however, when i am trying to use it in node file like:
var r = require('mymodulename') npm can't find it.
I think that i am missing something very small, but can't find what.
Thanks,
-D
Ok! Thanks for the answers.
It was totally my fault, and never put / for the main.
In my case i got :
"main": "/lib/mymodulename.js",
and it should be:
"main": "lib/mymodulename.js",
Thanks!

Resources