# VSCode REPL Namespaces/Modules

**URL:** <https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170>\
**Category:** VS Code\
**Tags:** namespaces\
**Created:** [August 24, 2023, 9:06pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170 "2023-08-24T21:06:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [August 24, 2023, 9:06pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/1 "2023-08-24T21:06:14Z")

</div>

How is this still happening? How are you living with this? I expected the [REPL module switching](https://github.com/JuliaLang/julia/pull/33872) released with Julia 1.9 to fix this issue.

```julia
(DataFrames) julia> x = 3 # Ctrl + Enter
3

(DataFrames) julia> x # Typed into REPL
ERROR: UndefVarError: `x` not defined

```

I have a clone of the DataFrames package open.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f35e5351af2a2c92e222ff40e99012d51b980cf.png)

I have activated the current directory environment.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/c/4cc788d39250a22f139b76c80a6717d410654e67.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/c/dc409115b930dd06ad6a7a3cf31cdb44a9a52cb5.png)

I have chosen the DataFrames module as the active module with the VSCode GUI.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/1/817a2291e94e2abf23094f710553f6b43adc70be.png)

I have used the new REPL functionality to change the active module to DataFrames with `Alt+m`.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/3/f3c5a298118895e55c5edfffcb0846cebb1a5fd3.png)

Related:

> <https://stackoverflow.com/questions/76274907/julia-code-sent-to-repl-is-a-different-environment-than-code-typed-into-repl>

[Feature Request: Lock Module · Issue #3024 · julia-vscode/julia-vscode (github.com)](https://github.com/julia-vscode/julia-vscode/issues/3024)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 25, 2023, 12:05am UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/2 "2023-08-25T00:05:12Z")

</div>

I don´t really use control-Enter often, so I can’t say if that worked before or not, but I’m using 1.10 now and it seems to be working as you describe (`x` is defined in the REPL).

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [August 25, 2023, 1:48am UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/3 "2023-08-25T01:48:08Z")

</div>

Yeah, I’m not experiencing this in 1.9.2 or 1.10.0-beta. `ctrl+Enter` is my primary way of coding, so very concerning that it could not work 🤯

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 25, 2023, 1:27pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/4 "2023-08-25T13:27:24Z")

</div>

Fixed by [https://github.com/julia-vscode/julia-vscode/pull/~3367](https://github.com/julia-vscode/julia-vscode/pull/~3367).

~~Needs a new release though, which is building a I write this.~~ Pre-release version 1.48.3 is out, so feel free to give that a go.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [August 25, 2023, 6:47pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/5 "2023-08-25T18:47:38Z")

</div>

It is working after the update if I set both the VSCode and REPL module to the same thing.

```julia
julia> using DataFrames # Typed into REPL (automatically changed VSCode module to DataFrames)
[Info: Precompiling DataFrames [a93c6f00-e57d-5684-b7b6-d8193f3e46c0]

julia> x # Typed into REPL (check not already defined)
ERROR: UndefVarError: `x` not defined

julia> x = 4 # Ctrl + Enter (define x)
4

julia> x # Typed into REPL (new definition still doesn't work)
ERROR: UndefVarError: `x` not defined

julia> DataFrames # Alt + m (change REPL module)

(DataFrames) julia> x # Typed into REPL (now defined variable exists)
4

```

Can you make the REPL module match the VSCode module automatically (even when the VSCode module hasn’t been manually selected)? I don’t understand why anyone would want these to be different.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/e/de1c923bd91ef7243ab79196a8bedc37146eb1a7.png)

I’m still pretty lost on how all these different switches go together and why. Sometimes the VSCode REPL behaves like I expect, but often it doesn’t, and it takes me a while to realize that the mistake is not in my code.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [December 14, 2023, 1:56pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/6 "2023-12-14T13:56:21Z")

</div>

I just use the VSCode terminal and start Julia using a bash script with the correct parameters. Using the Julia console from the plug-in is confusing me too much.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [December 14, 2023, 3:43pm UTC](https://discourse.julialang.org/t/vscode-repl-namespaces-modules/103170/7 "2023-12-14T15:43:29Z")

</div>

> [@Nathan\_Boyer](#):
>
> Can you make the REPL module match the VSCode module automatically (even when the VSCode module hasn’t been manually selected)? I don’t understand why anyone would want these to be different.  
> ![image](https://global.discourse-cdn.com/julialang/original/3X/d/e/de1c923bd91ef7243ab79196a8bedc37146eb1a7.png)

I created a GitHub Issue for this here:

> <https://github.com/julia-vscode/julia-vscode/issues/3492>
>
> When a module is selected in the VSCode GUI (either implicitly or explicitly), i…t doesn't actually change the REPL module.
> 
> Implicitly Selected (parentheses):
> !\[image\](https://github.com/julia-vscode/julia-vscode/assets/65452054/3746e6a2-e088-4678-8929-4ce1c9667128)
> Explicitly Selected (no parentheses):
> !\[image\](https://github.com/julia-vscode/julia-vscode/assets/65452054/36c60489-0bb4-4cf9-ae21-818eeceed72f)
> 
> \`\`\`julia
> julia\> x = 3
> 3
> 
> julia\> MyPackage.x
> ERROR: UndefVarError: \`x\` not defined
> Stacktrace:
> \[1\] getproperty(x::Module, f::Symbol)
> @ Base .\\Base.jl:31
> \[2\] top-level scope
> @ REPL\[3\]:1
> 
> julia\> Main.x
> 3
> \`\`\`
> 
> Currently, the module namespace can only be activated in the REPL manually with Alt+m.
> \`\`\`julia
> julia\> MyPackage # Alt + m
> 
> (MyPackage) julia\> y = 1
> 1
> 
> (MyPackage) julia\> MyPackage.y
> 1
> 
> (MyPackage) julia\> Main.y
> ERROR: UndefVarError: \`y\` not defined
> Stacktrace:
> \[1\] getproperty(x::Module, f::Symbol)
> @ Base .\\Base.jl:31
> \[2\] top-level scope
> @ REPL\[12\]:1
> \`\`\`
> 
> It would be very convenient for the VSCode REPL module selection to synchronize with the VSCode GUI module selection. The current behavior often yields very confusing errors when trying to use \`Julia: Execute Code in REPL\` and normal REPL typing together.
> \`\`\`julia
> julia\> z = 5 # Ctrl + Enter a line in a file within the MyPackage module
> 5
> 
> julia\> z + 2 # Typed into REPL
> ERROR: UndefVarError: \`z\` not defined
> \`\`\`
> I have personally been confused by this error several times, and I have seen several other beginners encounter it on \[Discourse\](https://discourse.julialang.org/t/executing-code-blocks-with-repl-workspace/107572) and \[StackOverflow\](https://stackoverflow.com/questions/76274907/julia-code-sent-to-repl-is-a-different-environment-than-code-typed-into-repl) as well.
