metalbear-co / mirrord-vscode

Connect your local process and your cloud environment, and run local code in cloud conditions.
https://mirrord.dev
MIT License
8 stars 10 forks source link

npm/node run doesn't get env set #26

Closed aviramha closed 1 year ago

aviramha commented 1 year ago

When running using npm/node the remote env isn't fetched.

aviramha commented 1 year ago

It might be that mirrord doesn't even load into it because they use dotenv script that loads it from file on the pod. It might be that we need to add SIP Patching?

t4lz commented 1 year ago

Does this only happen on vscode or also with the CLI?

eyalb181 commented 1 year ago

Only on VS Code - see here.

t4lz commented 1 year ago

Trying to reproduce in https://github.com/t4lz/npm-dotenv - could not reproduce the issue so far. Using dotenv with a config that points to a path that exists on the cluster, because the default path would not exist there. I am assuming this is also what is done where this issue was discovered.

aviramha commented 1 year ago

@t4lz Thanks for posting the project. The dotenv is external (meaning they use the cli to run their code) Add to your package.json a script that does dotenv -e FILE node index.js and then in your launch json run that.

t4lz commented 1 year ago

Ohh, so they're running dotenv-cli, right?

t4lz commented 1 year ago

Add to your package.json a script that does dotenv -e FILE node index.js and then in your launch json run that.

Did that and it still doesn't reproduce for me. Trying to think what I could be doing differently.

aviramha commented 1 year ago

Add to your package.json a script that does dotenv -e FILE node index.js and then in your launch json run that.

Did that and it still doesn't reproduce for me. Trying to think what I could be doing differently.

There's a specific launch configuration for npm run script. They used it. You can also do it if you go to package.json from the IDE and click debug next to the script you added.

aviramha commented 1 year ago

image

Ignore the scripts, just using this as an example :) (You can see a small debug button then you can choose what script to run)

t4lz commented 1 year ago

image

When running that way (clicking on the little "Debug" button above scripts), a run configuration with request type attach is used by vs-code: image And the env launch configuration field is only available for launch configurations of request type launch.

This of course means the layer is not injected into the process. This is not a SIP issue, it also wouldn't work on Linux.

Trying to think how we could support this way of launching. I don't think simply changing the request type would do, because it seems this configuration does not contain the information of which file to run etc. Also probably it's a different flow for the IDE.

t4lz commented 1 year ago

There's a specific launch configuration for npm run script. They used it.

Am I not using it in the commit I linked above? (not talking about the debug button in package.json now, but about vscode's launch.json) I followed vscode's Launch configuration support for 'npm' and other tools documentation.

aviramha commented 1 year ago

They had something like this:

    {
      "command": "npm run build:prod",
      "name": "Run npm start",
      "request": "launch",
      "type": "node-terminal"
    },