Search code examples
f#visual-studio-codeionide

The namespace or module is not defined


I am trying to work through the getting started docs for F# Visual Studio Code shows an error here

If I hover my mouse over the red squiggle I see the error message

The Namespace or module ClassLibraryDemo is not defined"

Here is the code for ClassLibaryDemo.fs

namespace ClassLibraryDemo

module PigLatin =
    let toPigLatin (word: string) =
        let isVowel (c: char) =
            match c with
            | 'a' | 'e' | 'i' |'o' |'u'
            | 'A' | 'E' | 'I' | 'O' | 'U' -> true
            |_ -> false

        if isVowel word.[0] then
            word + "yay"
        else
            word.[1..] + string(word.[0]) + "ay"

Solution

  • Please check the feedback in FSI when you execute #load ClassLibraryDemo.fs. You should see something like this:

    FSI: [Loading c:\Users\*****\Documents\Source\SO2017\SO180207\TestModule.fs] namespace FSI_0002.TestModule val testFunc : unit -> unit
    

    Most probably FSI can't find your file, either because the file name is misspelt or the file is in another directory. There could be other possible causes of not being able to see a namespace, for example not restoring a project, or corrupted cache (this I haven't seen in a while).