Environment Variable Conflicts when Developing a Node.js Project with Python Files in VS Code
Type: Bug
I'm facing an issue when developing a Node.js project that contains Python files in VS Code.
When I change the environment variables in the .env file, for example changing test=1 to test=2, and then rerun the Node environment (node --inspect test.js), the value of process.env.test is still 1.
When the Python files are detected, the Python extension is automatically activated in VS Code. This causes the Python virtualenv environment variables defined in the .venv or .env files to be loaded.
However, these environment variables are only intended for use in the Python runtime environment. Loading them overrides the .env file that defines the environment variables needed for the Node.js project.
As a result, the Node.js runtime does not have the correct environment configured and errors may occur.
This happens because the Python extension loads the Python-specific environment configuration, without considering the context that it is within a broader Node.js project. The loaded variables end up conflicting with those required for Node.js.
Has anyone else encountered this issue?
VS Code version: Code 1.86.2 (903b1e9d8990623e3d7da1df3d33db3e42d80eda, 2024-02-13T19:40:56.878Z) OS version: Windows_NT x64 10.0.22621 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz (8 x 2419) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
| Load (avg) | undefined |
| Memory (System) | 15.71GB (1.80GB free) |
| Process Argv | --crash-reporter-id f9438853-1ff6-47ad-a000-e9d8ef74c58c |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:30962250
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
b5d27386:30958190
a89i1917:30961429
7j2b6412:30964151
bg6jg535:30958357
This is a screenshot of the environmental contribution prompted by the console
It sounds like you may need to deactivate the virtualenv in the terminal? The python extension probably has some settings to configure this. Please file this on the Python extension.