Fable: Missing polyfill for trimStart and trimStart

Created on 7 Dec 2018  路  5Comments  路  Source: fable-compiler/Fable

Description

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.

Repro code

printfn "right trimmed string %s" ("    hello world".TrimStart())

Run this in and old browser like Internet Explorer 11, or Chrome 65

Expected and actual results

Expected console output: "right trimmed string hello world"

Actual: "Uncaught TypeError: e.trimStart is not a function"

Related information

Fable version: 2.0.11

Most helpful comment

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!

All 5 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

et1975 picture et1975  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

krauthaufen picture krauthaufen  路  3Comments

rommsen picture rommsen  路  3Comments

nozzlegear picture nozzlegear  路  3Comments