I am trying to install different packages using npm 8.19.2. For example yarn
sudo npm install --global yarn
All I get is
npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/yarn failed, reason: connect ETIMEDOUT 2606:4700::6810:1823:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-12-08T20_14_13_653Z-debug-0.log
I have a fresh installation of Ubuntu 22.04. According to this: http://www.amibehindaproxy.com/ I am not behind a proxy. I do not understand why I should be either. In fact, I don't know what it is.
node --version
v18.12.1
My goal is to get started with react. First step is to just run npx create-react-app my-app. But that does not work.
wget was also slow, then I found this Slow wget speeds when connecting to https pages.
Updating the network settings and disabling IPv6 did the trick.
I had multiple errors showing like the following:
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! network Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-09-28T23_48_25_332Z-debug.log
npm WARN old lockfile errno: -2,
npm WARN old lockfile code: 'ENOENT',
npm WARN old lockfile syscall: 'open',
npm WARN old lockfile path: '/home/./PhpstormProjects/vue-paper-dashboard-master/node_modules/postcss/node_modules/supports-color/package.json
I thought it was my internet connection but it turned out not to be like so.
I'm newbie to Vue.js so I was a little bit confused but I found my solution!
First I added these two values to ~/.npmrc:
timeout=60000
prefer-offline=true
then I have used the following command with deleting the node_modules folder:
npm cache clear --force
Then I added .npmignore to the root of my project
After that, I used
npm config set registry http://registry.npmjs.org/
but when I installed it with npm I checked as root like so :
sudo npm update
and it worked!
I have a server without internet access but a local npm. I'm trying to install a Node.js application, and one of the modules points to github. The package is part of one of the dependencies packages.
{
"name": "doccano",
"version": "1.0.0",
"description": "doccano is an open source annotation tools for machine learning practitioner.",
"author": "Hironsan",
"private": true,
"scripts": {
...
"dependencies": {
...
"#toast-ui/vue-editor": "^1.1.1",
...
}
}
Most packages are downloaded from local npm, but some point to github, and then I get the error:
npm install
...
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/seonim-ryu/Squire.git
npm ERR!
npm ERR! ssh: Could not resolve hostname github.com: Name or service not known
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
I can download the repository and upload it to the server, but how can I install the github packages?
It's pretty straight forward to install a package from a private registry:
npm install my-package --registry https://<private-registry-url>
This will add an entry to the package-lock.json:
"my-package": {
"version": "1.0.0",
"resolved": "https://<private-registry-url>/<some_path>/my-package-1.0.0.tgz",
"integrity": "sha1-Pjs/y9sEp49/OC8+8eEZFdwT3BQ="
},
So far so good, everything as expected.
The problem now is when you want to install all npm packages from a different device using npm install. This will fail with following error:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/my-package - Not found
npm ERR! 404
npm ERR! 404 'my-package#1.0.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'app'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<user>\AppData\Roaming\npm-cache\_logs\2019-08-06T08_33_05_103Z-debug.log
So it tries to fetch my-package from the public npm registry (https://registry.npmjs.org/my-package), but of course fails because my-package is located in the private registry.
Now this really breaks my understanding of package-lock.json..
Shouldn't npm look in the package-lock.json to see where the packages were resolved before? Instead it just assumes that it has to be in the public registry..
The other funny thing is, that it works once you manually installed the package with the --registry flag again:
npm install my-package --registry https://<private-registry-url> && npm i
And after that it will work everytime until you upgrade the version of my-package or switch the device..
I also tried npm ci command but without success (same error).
So how to properly install packages from private registries, so they can easily be installed on any other device using npm install?
I'm using npm run script to do tasks such as "build" and "test".
For example, my package.json looks like the following:
{
"name": "fulfillment-service",
"version": "1.0.0",
"description": "Endpoint for CRUD operations on fulfillment status",
"main": "src/server.js",
"scripts": {
"build": "tsc",
"test": "tape tests/*.js"
},
"dependencies": {},
"devDependencies": {
"typescript": "^1.8.10"
}
}
When I run npm run build and it is successful, the output is the following:
> fulfillment-service#1.0.0 build d:\code\fulfillment-service
> tsc
When I run npm run build and it fails, the output is the following:
> fulfillment-service#1.0.0 build d:\code\fulfillment-service
> tsc
src/server.ts(51,81): error TS2339: Property 'connection' does not exist on type 'IncomingMessage'.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! fulfillment-service#1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the fulfillment-service#1.0.0 build script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fulfillment-service package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs fulfillment-service
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls fulfillment-service
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! d:\code\fulfillment-service\npm-debug.log
This fills the entire console with useless information, and I have to scroll to the top to see why it failed.
Is there anyway to hide/silence the lines that start with npm ERR! during development?
You have to use npm run build --silent.
This isn't documented in npm help, npm help run, or anything else obvious, but with some searching on the internet you can find out that apparently it is documented in npm help 7 config. You can also use the loglevel option in .npmrc.
The --silent (short: -s) option suppresses:
The two lines beginning with > that say what command you're running.
npm ERR! errors.
Creating an npm-debug.log if there's an error.
Note: using npm scripts to run other npm scripts may require you to use --silent more than once. Example package.json:
{
. . .
"scripts": {
"compile": "tsc",
"minify": "uglifyjs --some --options",
"build": "npm run compile && npm run minify"
}
}
If you do npm run build and TypeScript finds an error, then you'll get the npm ERR! from both scripts. To suppress them, you have to change the build script to npm run compile --silent && npm run minify and run it with npm run build --silent.
Add file .npmrc to project and put in the file loglevel=silent.
A variation on other posts related to this (but not enough cred to comment!), and a little quicker/convenient as a stop gap is that you can change the exit status of processes that npm is running in situ, so that it doesn't think it failed. Obviously this will not stop chained commands from running after it. Sh does boolean evaluation similar to JS, just add || true on the end, e.g.:
"myscript": "eslint || true"
Hopefully this is also obvious enough that other devs can find it before they come looking for you!
There is an issue filed on npm: run-scripts are too noisy while used in development #8821 (also mentioned in a comment above)
In the discussion in that issue, a couple of people have mentioned creating an alias e.g. npr (utilizing the --silent option gcampbell describes in his/her answer). Although --silent can hide some npm type issues such as a malformed package.json, this seems like a reasonable solution for now.
alias npr='npm run --silent $*'
One other thing from that discussion which may be worth looking into, although it is yet another tool, is yarn which is described on a facebook blog post.
As others have noted, the problem with --silent is you lose all output. There's another way that seems to work for most cases:
npm run something 2>/dev/null
If one of the binaries you are running happens to write to stderr, then that will be suppressed. But most node stuff writes to stdout, so it shouldn't be a problem.
Of course this will work only in a shell environment that supports output redirection.
In case if you've created a custom script and it returns with the NPM error (even there's no error), add
process.exitCode = 0;
at the end of the script to avoid error.