Reputation: 337
I use SAFE stack. For email validation I imported EmailValidation via paket. Code compiles and runs; I can even peek into EmailValidation sources via debugger. At run time I face an exception:
Uncaught ReferenceError: EmailValidation_EmailValidator_Validate_C556D7B is not defined
at isEmailAndPasswordValid (Index.fs.js?b47d:47)
at containerBox (Index.fs.js?b47d:184)
at view (Index.fs.js?b47d:216)
at eval (App.fs.js?8a0c:24)
at eval (Util.js?2ca6:555)
at uncurriedFn (Util.js?2ca6:520)
at Object.eval [as render] (common.fs.js?a3d0:73)
at Components_LazyView$1.render (common.fs.js?a3d0:56)
at finishClassComponent (react-dom.development.js?db4e:17160)
at updateClassComponent (react-dom.development.js?db4e:17110)
Navigated to source in browser:
export function isEmailAndPasswordValid(data) {
const em = EmailValidation_EmailValidator_Validate_C556D7B(data.Email, false, false);
const p = !isNullOrWhiteSpace(data.Password);
if (em) {
return p;
}
else {
return false;
}
}
My F# code :
let isEmailAndPasswordValid (data: LoginInfo)=
let em = EmailValidation.EmailValidator.Validate data.Email
//let em = String.IsNullOrWhiteSpace data.Email |> not
let p = String.IsNullOrWhiteSpace data.Password |> not
em && p
When I use simple String.IsNullOrWhiteSpace, everything is fine. Why I can not use imported code in Fable?
Upvotes: 2
Views: 277
Reputation: 26233
Per the docs:
Please note that not all Nuget libraries will work with Fable. Refer to the library documentation to check if it's Fable-compatible.
A compatible library, amongst other things, needs to include its F# source code in the NuGet package so Fable can transpile this to JavaScript.
From what I can see, EmailValidation
is written in C#, so this isn't going to work.
Upvotes: 2