Using nvm to switch between npm versions and dealing with init.author.name needs to be init-author-name - npm

I was on npm version 6 and when I moved to npm version 8.19.3, I got the warnings below whenever I issued any command:
npm --version
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
npm WARN config init.author.url Use `--init-author-url` instead.
npm WARN config init.license Use `--init-license` instead.
npm WARN config init.version Use `--init-version` instead.
8.19.3
I searched and found another user asked how to fix this warning, see this question, so I updated my $HOME/.npmrc file to use the new format (see this answer) and it worked.
However, because I use nvm to switch between different versions of npm, I would like to have a solution that works for both the old and new versions of npm.
I tried to include syntax's for both the old and new config names as shown next:
# For npm 8.? and higher
init-author-name=Example name
init-author-email=name#example.com
init-author-url=https://www.example.com
init-license=MIT
init-version=1.0.0
# For npm < 8.?
init.author.name=Example name
init.author.email=name#example.com
init.author.url=https://www.example.com
init.license=MIT
init.version=1.0.0
But the above didn't work. I was forced to delete the older syntax names to get rid of the warning messages.
So my question is:
(Q) Is there a syntax that I can use that works for both the older versions of npm and the newer versions of npm? Basically, I'd like not to have to manually edit my .npmrc file when I switch between older and newer versions when I use commands like:
nvm use 12.13.1
# Now I need the old config names (like init.author.name)
nvm use 8.19.3
# Now I need the new config names (like init-author-name)
As I said, I tried including both the old config names and the new names, but it didn't work. I was forced to remove the old names to get rid of the warnings. IMO, this is a bug.
Is there a solution to this problem?
Searching for a solution
I sited the question that I found on this topic:
https://stackoverflow.com/a/72113809/3281336

Related

NPM equivalent for "npm:#user/package-name" version in package.json?

I saw this in a package.json file:
"react-native-wheel-picker": "npm:#gregfrench/react-native-wheel-picker",
That doesn't match the tarball, http, or git dependency formats documented in the NPM docs. Looks like it's a yarn convention, because running yarn installed that dependency without complaints from the start script (which otherwise would complain warn Package react-native-wheel-picker has been ignored because it contains invalid configuration. Reason: Cannot find module 'react-native-wheel-picker/package.json').
What does that "version" string mean, why not use "#gregfrench/react-native-wheel-picker" directly, and what would be the package.json equivalent that would allow npm to function correctly?
The npm compatible dependency specification would look like following:
"#gregfrench/react-native-wheel-picker": "<version>"
As I see on npmjs.com the latest version for #gregfrench/react-native-wheel-picker is 1.2.3 so if the latest version is needed than following should be in the package.json:
"#gregfrench/react-native-wheel-picker": "1.2.3"
If you don't want to have an exact version there are some possibilities like using ^,~, >=.. characters with the version string. These possibilities are documented here.

npm publish got package name too similar to existing packages

I want to publish my package to npm. the error I get is: Package name too similar to existing packages
403 Forbidden - PUT https://registry.npmjs.org/mypack.... - Package name too similar to existing packages; try renaming your package to '#user../mypackage...' and publishing with 'npm publish --access=public' instead
but when I try to install:
npm I mypackage...
I get the error not found:
npm ERR! 404 Not Found - GET https://registry.npmjs.org/mypackage... - Not found
Is there a way to check if the name is good for npm and not just guess? because I can't delete the package after I publish..
To check similar names you can use validate-name:
Install:
$ npm install -g validate-name
Use:
$ validate-npm-name my-module
$ validate-npm-name my-package --max-age 1440
What it does:
This command checks whether similar names exist in npm registry.
Upon first use, it downloads full list of module names (apprx. 150MB as of this writing) to check similarity. Subsequent downloads are much smaller, because it only downloads updates since last download.
I created this module by following script suggested by #RobC in OP's comments. It is open source (MIT).
As described in the original script, it is a best effort, because similarity rules are not formally documented by npm.
This behavior has been documented on the npm blog under New Package Moniker rules:
We’ve recently made some changes to how package naming works to better fight typosquatting, and help package authors pick names that stand out.
If you are publishing a new package—that is, a package that has not been in the registry before, we remove punctuation from its name and compare it to existing package names. If the names are identical without punctuation, we do not allow the package to be created.
Because react-native exists, no one can publish variations like:
reactnative
react_native
react.native

npm install fail with some package not found on some server

I am on different servers and run npm install
One server is ok. Another failed showing below error:
no matching version found for es-abstract#1.14.0
I tried npm ci. Same deal.
Then I did npm install es-abstract-1.14.0.tgz
But the size node_modules/ are different. I am using du -shc --apparent-size node_modules/ to ignore the sparse files within the folder. Why?
Could I accept that this is the network issue of the failed server? And just keep doing this? I mean, is the installation still going to be ok in this way?
At the time that this answer was written, there are 33 release versions for es-abstract on github, but only 32 release versions are listed on its npm registry. The missing version in the registry is 1.14.0.
Perhaps on one of your servers, you had this package cached (maybe it was previously listed on the NPM registry?, or maybe from downloading it from github?), and on the other server you did not have this package cached.
I had this same error message when trying to npm install a project from github.
In my situation, the es-abstract package was not explicitly listed in the package.json file, but it was a dependency of another package. Therefore I explicitly added it with the next highest version listed on the registry, and it worked.
e.g.
"dependencies": {
"es-abstract": "1.14.1",
...
Just a guess, but maybe 1.14.0 used to be listed on the registry, but now it's not?

VS Code terminal fails to use npm version from nvm

I'm using nvm on my Terminal and successfully installed node 10.2.1, which also installed npm 6.1.0. However, when I go to my VS Code editor, it gives me warnings in the integrated terminal for:
npm WARN npm npm does not support Node.js v10.2.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4,6, 7, 8, 9.
Turns out, it is actually using npm 5.5.1 (npm -v).
I check to see what's up with that and tried to dig further and eventually used: which npm on both integrated terminal and Mac's CLI.
Mac's Terminal shows:
/Users/Aiz/.nvm/versions/node/v10.2.1/bin/npm
VS Code's Terminal shows:
/usr/local/bin/npm. Which is interesting, because if you do which node in this terminal, it results in the appropriate /Users/Aiz/.nvm/versions/node/v10.2.1/bin/node.
I'm not sure how to get my VS Code terminal to point to the appropriate npm install through nvm. Not sure if it helps, but I checked npm get prefix and npm -g bin to find /Users/Aiz/.nvm/versions/node/v10.2.1. The only difference I'm finding is where each terminal is using npm from.
I ended up looking through VS Code issues on GitHub and came across something relevant to NVM and node issues. It fixed my issue since the underlying cause was the same.
Essentially what happened is that I had a global install of node before that I removed prior to using NVM but hadn't removed my global install of npm. This was causing conflicts in VS Code's terminal (not Mac's terminal). In order to fix this, you essentially have to find the symlink for which npm and remove the node_modules and npm associated recursively.
Here's the link you'll need: https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched.
Don't forget to restart your editor after.
Another solution is to implement this. https://medium.com/#kinduff/automatic-version-switch-for-nvm-ff9e00ae67f3
Basically, nvm will check for a .nvmrc and switch or default each time you go to a new directory in shell.
It does have a dependency on zsh.
The fix for me on Ubuntu:
A.) sudo apt-get remove nodejs npm
B.) Removed lines in my .bashrc that added the npm package directory to the path.
C.) Restart VS Code.
I doubt step A is necessary. But B and C certainly are.

npm install "No compatible version found" for everything

Upon executing the following command:
npm install #angular/animations#'^5.2.0' #angular/common#'^5.2.0' #angular/compiler#'^5.2.0' #angular/compiler-cli#'^5.2.0' #angular/core#'^5.2.0' #angular/forms#'^5.2.0' #angular/http#'^5.2.0' #angular/platform-browser#'^5.2.0' #angular/platform-browser-dynamic#'^5.2.0' #angular/platform-server#'^5.2.0' #angular/router#'^5.2.0' typescript#2.4.2 rxjs#'^5.5.2'
I get messages saying that no compatible version of found for rxjs. Then when I remove the specific version, it says no compatible version is found for angular/animations. Then angular/common. Etc etc.
I'm pretty sure these versions are valid, since they're the ones recommend by this Angular upgrade tool (https://angular-update-guide.firebaseapp.com/) and I can also see the "valid install target" list, which includes the versions I'm trying to install.
I know our project's dependencies are in some special repository somewhere (Artifactory, I think?) so maybe this is happening because these versions are not in the repo NPM is looking at.
Is there a way to fix this for testing purposes before committing to having to install the new versions in the repo? In other words, how do I point NPM at the NPM repo rather than the company's repo?
Well, the answer I was looking for was here:
How to specify registry while doing npm install with git remote url?
However that didn't actually work.
The problem was simply a syntax issue. After I removed all the quotes from my command so it looked like the following command, it worked
npm install #angular/animations#^5.2.0 #angular/common#^5.2.0 #angular/compiler#^5.2.0 #angular/compiler-cli#^5.2.0 #angular/core#^5.2.0 #angular/forms#^5.2.0 #angular/http#^5.2.0 #angular/platform-browser#^5.2.0 #angular/platform-browser-dynamic#^5.2.0 #angular/platform-server#^5.2.0 #angular/router#^5.2.0 typescript#2.4.2 rxjs#^5.5.2