Why does overrides not work:
{
"dependencies": {
"#angular/animations": "^15.0.0",
"#angular/cdk": "15.1.2",
"#angular/common": "15.1.2",
...
},
"overrides": {
"#angular/animations": "15.1.2",
}
}
when this works:
{
"dependencies": {
"#angular/animations": "15.1.2",
"#angular/cdk": "15.1.2",
"#angular/common": "15.1.2",
...
}
}
Is my override telling package.json to set "#angular/animations" to 15.1.2?
The former throws an EOVERRIDE error when I run npm install or npm install --force:
npm ERR! code EOVERRIDE
npm ERR! Override for #angular/animations#^15.0.0 conflicts with direct dependency
The overrides documentation says this:
You may not set an override for a package that you directly depend on
unless both the dependency and the override itself share the exact
same spec. To make this limitation easier to deal with, overrides may
also be defined as a reference to a spec for a direct dependency by
prefixing the name of the package you wish the version to match with a
$.
{
"dependencies": {
"foo": "^1.0.0"
},
"overrides": {
// BAD, will throw an EOVERRIDE error
// "foo": "^2.0.0"
// GOOD, specs match so override is allowed
// "foo": "^1.0.0"
// BEST, the override is defined as a reference to the dependency
"foo": "$foo",
// the referenced package does not need to match the overridden one
"bar": "$foo"
}
}
Is the documentation saying that
BAD: The override can't be newer than the dependency.
GOOD: The override can be the same as the dependency. This what I'm doing.
BEST: I don't understand what this.
The main purpose of overrides is to manage dependencies of your dependencies.
So if you would like to override one of your package which is in your direct deps (#angular/animations is in your direct deps) then there are 2 options:
1)
{
"dependencies": {
"#angular/animations": "^15.0.0",
},
"overrides": {
"#angular/animations": "$#angular/animations",
}
}
All #angular/animations packages in your deps tree will be replaced to ^15.0.0, but there is limitation you mentioned (override must contain the same version as dependencies contains).
2)
{
"dependencies": {
"#angular/animations": "^15.0.0",
},
"overrides": {
"some_package":{"#angular/animations": "any version"},
}
}
You may use nested syntax (replace dep version for a specific package) and then there is not limitation for the same version.
About 'BEST' option from the docs. You may use prefix $ plus just name of the package and then you will avoid yourself to update version inside override field each time when version inside dependencies will be updated.
Related
I have a project using Bootstrap and need to enable Bootstrap's cssgrid when the user runs [npm install] so I need to add this in package.json
-- Package.json
{
"name": "PROJECT",
"description": "DESC",
"dependencies": {
"backbone": "^1.4.1",
"bootstrap": "^5.3.0-alpha1", // Need to add enable-cssgrid variable here!!
"jquery": "^3.6.3"
}
}
How to solve that so the client can get the correct Bootstrap module?
What is the 'dev' dependency version?
E.g. here:
{
"name": "ntbjpb--run",
"version": "0.0.0",
"private": true,
"dependencies": {
...
"#progress/kendo-angular-progressbar": "^0.2.3",
"#progress/kendo-angular-toolbar": "dev",
...
},
"scripts": {
"ng": "ng",
"start": "ng serve",
...
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.901.1",
"#angular/cli": "~9.1.1",
...
}
}
"#progress/kendo-angular-toolbar": "dev"
I tried to google it, but all my research comes to the devDependencies which is not what I am looking for I guess.
The best match I got was this question. But the answer to it states:
So using dev as a version number is not allowed.
While we can clearly see from the stackblitz example I linked above that it is not the case and the dev is allowed to be used in the place of the version number.
That string mean install the module tag <dev> as reported in docs npm install [<#scope>/]<name>#<tag>
In fact, looking the versions of that module you will see the tag defined:
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"
}
}
]
]
}
}
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.
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.