Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import npm specifier modules due to firewall #837

Closed
Tracked by #968 ...
justinmchase opened this issue Apr 13, 2023 · 9 comments
Closed
Tracked by #968 ...

Cannot import npm specifier modules due to firewall #837

justinmchase opened this issue Apr 13, 2023 · 9 comments

Comments

@justinmchase
Copy link

justinmchase commented Apr 13, 2023

Describe the bug
I cannot configure NPM_CONFIG_REGISTRY in the vscode extension.

https://deno.com/blog/v1.29#custom-registry-support-via-environment-variable

To Reproduce

  1. Connect to a corporate VPN which blocks npm
  2. Setup an Artifactory proxy
  3. Attempt to import something with an npm specifier
import * as express from "npm:express";

Expected behavior

I expect to be able to have this succeed by importing through the proxy.

I would imagine it could be as simple as adding an option npmRegistry to the settings which would set that env variable before invoking deno.

{
  "deno.npmRegistry": "<url>"
}

Screenshots

Screen Shot 2023-04-13 at 9 38 02 AM

Screen Shot 2023-04-13 at 9 37 55 AM

Versions

vscode: 1.67.2 deno: 1.32.4 extension: v3.17.0

@oscar6echo
Copy link

I reach a similar wall.

Config: vscode: 1.89.1, deno: 1.43.3, extension: 3.37.1

Behind a corp proxy I can use deno CLI with specific env variables:

  • HTTP_PROXY, HTTPS_PROXY, NO_PROXY
  • DENO_CERT to use certificates including corp ones

But vscode deno extension does not seem aware of proxy env variables. As a result remote links appear underlined in red wiggle and "Uncached or missing remote URL" on hover e.g.:

image

image

NOTE: Here they look ok as I write from outside corp env

An unfortunate consequence for dev exp is that all objects from these outside links are considered any which breaks type checks and forces to use // deno-lint-ignore no-explicit-any in the rest of the code.

On the other hand the certificate config can be set in .vscode/settings.json:

{
    "deno.enable": true,
    "deno.cache": ".cache",
    "deno.tlsCertificate": "/path/to/corp/ca-certificates.crt",
    "editor.formatOnSave": true,
    "editor.formatOnPaste": true,
    "[typescript]": {
        "editor.defaultFormatter": "denoland.vscode-deno"
    }
}

A surprising fact is that even if vscode proxy settings are explicitly set (in field below) this does not help vscode deno extension - as opposed to other extensions of vscode.

image

This limitation is a serious drag for deno use in a corp env I'm afraid.
Surely you know it already but just wanted to describe this problem precisely.

@nayeemrmn nayeemrmn self-assigned this Jun 29, 2024
@nayeemrmn
Copy link
Collaborator

@oscar6echo I've checked that HTTP_PROXY and all other env vars are passed from the user's env to the language server (which handles module downloads) by the extension. How do you set the env vars, and have you tried clearing the cache?

@nayeemrmn
Copy link
Collaborator

@justinmchase Is it acceptable to set NPM_CONFIG_REGISTRY in your user profile before opening VSCode? That will be passed to the language server.

@justinmchase
Copy link
Author

I'm pretty sure I do have it set that way but will check again and yeah it would be ok to pick it up that way in my case, since it's a machine global. But I could see someone still wanting a per repo setting.

@oscar6echo
Copy link

@oscar6echo I've checked that HTTP_PROXY and all other env vars are passed from the user's env to the language server (which handles module downloads) by the extension. How do you set the env vars, and have you tried clearing the cache?

What do you call user's env ? Do you mean the terminal from which to start VS Code ? If so, it may not apply in my case as I use VS Code remote SSH to connect to a machine. The doc warns about it, if I understand well. This is why I explicitly tried the HTTP(S)_PROXY env vars via VS Code settings (see last part of my comment , keeping in mind I could not screen shot the exact thing as I write from outside corp env - in particular the visual is a bit different for a remote host) but it did not work while it does for other extensions (tested).

Suggestion: the vscode_deno extension could read env vars from an env file passed in deno settings say (or similar):

{
 "deno.proxyEnvFile": "path/to/env/file.env"
}

This optional setting would override the current behavior - and be pleasantly explicit and easy to understand,
What do you think ?

@nayeemrmn
Copy link
Collaborator

@oscar6echo Version 3.38.0 of the extension has been released. You can now have settings like:

{
  "deno.envFile": "path/to/env/file.env"
}
{
  "deno.env": {
    "HTTP_PROXY": "http://localhost:8080"
  }
}

@justinmchase Please try this with NPM_CONFIG_REGISTRY also. But if you had it configured on your machine it should have already worked. It may be a separate issue.

@oscar6echo
Copy link

@nayeemrmn thx for the super fast release ! 👏 Much appreciated !
I'll test next week when back in the office.

@oscar6echo
Copy link

I'll test next week when back in the office.

@nayeemrmn It does work fine (unsurprisingly) and this is really pleasant. Thx again !

@bartlomieju
Copy link
Member

Great to hear that @oscar6echo, I'll close this issue for now. Let me know if you face any other problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants