Fable 2 seems to translate a String.TrimStart call with the String.prototype.trimStart function.
The methods trimStart and trimLeft are at the moment a proposal for the next EcmaScript Version, but not standardized yet. It's also lacking support in older Browser version or Internet Explorer 11.
printfn "right trimmed string %s" (" hello world".TrimStart())
Run this in and old browser like Internet Explorer 11, or Chrome 65
Expected console output: "right trimmed string hello world"
Actual: "Uncaught TypeError: e.trimStart is not a function"
Fable version: 2.0.11
Are you using the webpack config template and @babel/polyfill?
@SCullman I'm using @babel/polyfill as an entry and have this config:
{
loader: "fable-loader",
options: {
babel: {
presets: [
"@babel/preset-env",
{
useBuiltIns: "entry",
modules: false,
targets: ["last 4 versions", "ie >= 11"]
}
]
}
}
}
// edit
And useBuiltIns set to "usage" is also not working
And it is also installed via yarn add @babel/polyfill? I guess otherwise it won't compile.
Both trimStart and trimLeft are part of core-js since 2.5.0 , which is the foundation of the @babel/polyfill. In my current env, core-js is of version 2.5.1.
Hi @nilshelmig! Did you check @SCullman latest comment (thanks a lot for the help, btw!)? Did it help?
It's working now! I seems that core-js was outdated, but I don't know why. I have @babel/polyfill installed at the latest version, which brings core-js 2.5 as a dependency, but the files es7.string.trimLeft and es7.string.trimRight weren't in the core-js module directory.
I just deleted the node_modules folder and execute yarn install again.
Thanks for your help!
Most helpful comment
It's working now! I seems that core-js was outdated, but I don't know why. I have
@babel/polyfillinstalled at the latest version, which bringscore-js2.5 as a dependency, but the fileses7.string.trimLeftandes7.string.trimRightweren't in the core-js module directory.I just deleted the node_modules folder and execute
yarn installagain.Thanks for your help!