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

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

Closed
aviramha opened this issue Jul 12, 2023 · 12 comments · Fixed by #27
Closed

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

aviramha opened this issue Jul 12, 2023 · 12 comments · Fixed by #27
Assignees

Comments

@aviramha
Copy link
Member

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

@aviramha aviramha transferred this issue from metalbear-co/mirrord-intellij Jul 12, 2023
@aviramha
Copy link
Member Author

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 t4lz self-assigned this Jul 12, 2023
@t4lz
Copy link
Member

t4lz commented Jul 12, 2023

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

@eyalb181
Copy link
Member

Only on VS Code - see here.

@t4lz
Copy link
Member

t4lz commented Jul 12, 2023

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
Copy link
Member Author

@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
Copy link
Member

t4lz commented Jul 13, 2023

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

@t4lz
Copy link
Member

t4lz commented Jul 13, 2023

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member

t4lz commented Jul 13, 2023

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
Copy link
Member

t4lz commented Jul 13, 2023

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
Copy link
Member Author

They had something like this:

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

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

Successfully merging a pull request may close this issue.

3 participants