lukehaas / RunJS

RunJS is a JavaScript playground for macOS, Windows and Linux. Write code with instant feedback and access to Node.js and browser APIs.
https://runjs.app
2.01k stars 43 forks source link

Unable to access the NPM repository behind a proxy #535

Closed silver-mx closed 1 year ago

silver-mx commented 1 year ago

I am behind a proxy and RunJs cannot reach the NPM repository. I checked the documentation but could not find how to set up the proxy settings.

It seems that RunJs uses a special npm client and it is not taking the global NPM configuration. How should I do the configuration then?

See the debug logs:

{
  "version": "2.7.5",
  "platform": "win32",
  "arch": "x64",
  "activated": true,
  "logs": [
    {
      "path": "C:\\Users\\diego\\AppData\\Roaming\\runjs\\logs\\main.log",
      "lines": [
        "[2023-02-20 10:09:23.373] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search rxjs --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_08_13_081Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:12:02.929] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search react --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=react&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=react&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_10_52_692Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:14:47.057] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search react --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=react&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=react&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_13_36_821Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:15:07.050] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search jquery --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=jquery&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=jquery&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_13_56_814Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:18:10.761] [error] Error: Command failed: taskkill /pid 39788 /T /F\nERROR: The process \"39788\" not found.",
        "\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at ChildProcess.emit (node:domain:475:12)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)  ERROR: The process \"39788\" not found.",
        "",
        "[2023-02-20 10:20:31.446] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search rxjs --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_19_21_212Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:24:37.059] [error] [renderer] Error: Command failed: \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\diego\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" search rxjs --json --no-description --userconfig=\"\"\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n{\n  \"error\": {\n    \"code\": \"ENOTFOUND\",\n    \"summary\": \"request to https://registry.npmjs.org/-/v1/search?text=rxjs&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\",\n    \"detail\": \"This is a problem related to network connectivity.\\nIn most cases you are behind a proxy or have bad network settings.\\n\\nIf you are behind a proxy, please make sure that the\\n'proxy' config is set properly.  See: 'npm help config'\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\diego\\npm-cache\\_logs\\2023-02-20T09_23_26_825Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:841:15)\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "[2023-02-20 10:26:24.427] [error] Error: Command failed: taskkill /pid 38012 /T /F\nERROR: The process \"38012\" not found.",
        "\n    at ChildProcess.exithandler (node:child_process:407:12)\n    at ChildProcess.emit (node:events:527:28)\n    at ChildProcess.emit (node:domain:475:12)\n    at maybeClose (node:internal/child_process:1092:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)  ERROR: The process \"38012\" not found.",
        "",
        ""
      ]
    }
  ]
}
lukehaas commented 1 year ago

RunJS doesn't use the global NPM config because the settings can potentially cause unpredictable problems, such as overriding the install location. There currently isn't a way to configure proxy settings for NPM in RunJS, but I will consider how this could be implemented in a future release.

silver-mx commented 1 year ago

@lukehaas I see the debug logs that the NPM search expects an argument like --userconfig=\"\". Is there any undocumented way (even if it is a bit hacky) like adding a configuration somewhere that could make this work?

lukehaas commented 1 year ago

No, this is hard-coded. Without this argument being set, NPM would attempt to use the global config.

guitarama commented 1 year ago

I have to use NODE_EXTRA_CA_CERTS for my command line installs due to corporate web proxy having a self-signed cert. It would be amazing to be able to specify that as well.

lukehaas commented 1 year ago

@silver-mx I've just pushed a pre-release version of RunJS that will pick up a .npmrc file if it's located inside the app data directory for RunJS. On Mac, this is here: ~/Library/Application\ Support/runjs

The pre-release is here: https://github.com/lukehaas/RunJS/releases/tag/v2.8.0 It would be great if you could try it out and let me know if it solves this issue for you.

silver-mx commented 1 year ago

Thanks @lukehaas, I tested the released version today and the search worked fine, but then the installation of the NPM package failed. I tried with rxjs for example, and the logs showed the following error when the installation failed:

NOTE: I included the .npmrc file in the folder C:\Users\myuser\AppData\Local\Programs\runjs. The .npmrc includes proxy and https_proxy.

"[2023-03-13 08:57:29.473] [error] [renderer] Error: Command failed: \"C:\\Users\\myuser\\AppData\\Local\\Programs\\runjs\\RunJS.exe\" \"C:\\Users\\myuser\\AppData\\Local\\Programs\\runjs\\resources\\app.asar.unpacked\\node_modules\\npm\\bin\\npm-cli.js\" install -S --save-exact --ignore-scripts --force --progress=false --audit=false --userconfig=\"C:\\Users\\myuser\\AppData\\Roaming\\runjs\\.npmrc\" rxjs@7.8.0\nnpm WARN using --force Recommended protections disabled.\nnpm ERR! code ENOTFOUND\nnpm ERR! syscall getaddrinfo\nnpm ERR! errno ENOTFOUND\nnpm ERR! network request to https://registry.npmjs.org/rxjs failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org\nnpm ERR! network This is a problem related to network connectivity.\nnpm ERR! network In most cases you are behind a proxy or have bad network settings.\nnpm ERR! network \nnpm ERR! network If you are behind a proxy, please make sure that the\nnpm ERR! network 'proxy' config is set properly.  See: 'npm help config'\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     C:\\Users\\myuser\\npm-cache\\_logs\\2023-03-13T07_56_19_055Z-debug-0.log\n\n    at __node_internal_genericNodeError (node:internal/errors:856:15)\n    at ChildProcess.exithandler (node:child_process:409:12)\n    at ChildProcess.emit (node:events:513:28)\n    at maybeClose (node:internal/child_process:1093:16)\n    at ChildProcess._handle.onexit (node:internal/child_process:302:5)",
lukehaas commented 1 year ago

@silver-mx thanks for the update. Are you able to successfully install NPM packages via the terminal?

silver-mx commented 1 year ago

Good news. It works! The only issue was that the .npmrc with the proxy/https_proxy (I have both) configurations must be placed in the location:

C:\Users\myuser\AppData\Roaming\runjs\.npmrc

Previously I had it in C:\Users\myuser\AppData\Local\Programs\runjs\.npmrc and strangely, the search was working but not the installation. I checked the debug logs and it clearly tries to use the one in C:\Users\myuser\AppData\Roaming\runjs\.npmrc.

Closing the ticket, thanks for the help and the great work with RunJS 👍