jay
jay copied to clipboard
Running 'jay' hangs for ~3 minutes when running behind network proxy on Windows
Simply running jay from the console on Windows hangs for about 3 minutes before eventually displaying the node, npm, and jay-repl versions (and prompt). This only happens when behind a network proxy. I've done some investigation and the code that causes this to hang is the following line in cli.ts.
version('npm', execa.sync('npm', ['-v']).stdout)
It appears that this is caused by a "bug" in npm. Apparently, version 4.4.0 of npm added an update check feature. When running npm commands via child_process the network proxy is not observed and thus a network timeout occurs after 3 minutes.
A workaround for this is to set the NO_UPDATE_NOTIFIER environment variable to false. I tested the following code that resolves this issue:
function getNpmVersion() {
const env = {
...process.env,
NO_UPDATE_NOTIFIER: "true",
};
const result = execa.sync('npm', ['-v'], { env });
return result.stdout;
}
Could you fix this? I tried cloning the repo to do a pull request but I am getting errors doing that too (which also appear to be network proxy related!).
node v10.13.0 npm v6.4.1 jay-repl v0.2.2
Thanks, Jonathan
can't reproduce this myself unfortunately - does installing modules via jay work for you when behind the proxy?
$ jay
> require('lodash')
I am not surprised that you cannot reproduce this :) Interestingly, after changing absolutely nothing jay is starting up right away now - no more hanging. Since I have started using jay I have consistently been having these hangs. So i'm not sure what changed. Just yesterday this was taking 3 minutes.
I thought I could require modules. I had installed lodash previously and it now loads fine from cache:
[email protected] imported from node_modules.
But maybe I had been off my network proxy when I loaded lodash the first time.
Now I cannot load any packages:
> require('ramda')
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.<anonymous> (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\moduler.js:256:33)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\moduler.js:5:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
{ C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\node_modules\resolve\lib\sync.js:76
throw err;
^
Error: Cannot find module 'ramda' from 'C:\Users\jonathan\AppData\Local\jay-repl-nodejs\Cache\packages\lib'
at Function.module.exports [as sync] (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\node_modules\resolve\lib\sync.js:74:15)
at _resolve (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\moduler.js:177:44)
at _require (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\moduler.js:191:39)
at evalmachine.<anonymous>:1:1
at Script.runInContext (vm.js:107:20)
at Object.<anonymous> (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\eval.js:94:41)
at Generator.next (<anonymous>)
at C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\eval.js:7:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\jay-repl\dist\eval.js:3:12) code: 'MODULE_NOT_FOUND' }
FYI, my C:\Users\jonathan\AppData\Local\jay-repl-nodejs\Cache\packages directory is empty.
I figured out the cause of the error I was getting when attempting to require un-cached packages. It turns out that npm was unable to resolve my root CA file for my proxy. That was preventing me from even being able to run npm:
> npm
Error: Unknown system error -214427238: Unknown system error -214427238, open 'D:\Development\ZscalerRootCertificate-2048-SHA256.crt'
TypeError: Cannot read property 'get' of undefined
at errorHandler (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\utils\error-handler.js:205:18)
at C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\bin\npm-cli.js:78:20
at cb (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\npm.js:228:22)
at C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\npm.js:266:24
at C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\config\core.js:83:7
at Array.forEach (<anonymous>)
at C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\config\core.js:82:13
at f (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\node_modules\once\once.js:25:25)
at finalize (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\config\core.js:189:14)
at Conf.afterCARead (C:\Users\jonathan\AppData\Roaming\nvm\v10.13.0\node_modules\npm\lib\config\load-cafile.js:14:14)
After fixing that I am now back to being able to require packages. And I can still run jay quickly. It starts up right away now. I have no idea why the behavior suddenly changed. 🤷
jay is back to taking 3 minutes to start up. I can't explain why it started up quickly previously. Can you make the change above to disable npm's update notifier (or just stop displaying the npm version)?