question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android padStart is undefined, likely needs to be polyfilled

See original GitHub issue

When testing on Android 5.0+ (Google API 22+) I found that calls to padStart would result in “undefined is not a function”. Polyfilling it manually resolved the issue in Android 5.0+. My polyfill fix was a verbatim copy/paste of the polyfill example on MDN’s padStart . This error does not happen when debugging remotely. If my understanding is correct, this is due to differences in Chrome’s JS engine vs React Natives implementation.

I found related issue #17442 where this error was occurring on iOS. I opened a separate issue because this was happening on Android.

Environment

#####Environment: OS: macOS Sierra 10.12.6 Node: 9.5.0 Yarn: Not Found npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003

#####Packages: (wanted => installed) react: ^16.2.0 => 16.2.0 react-native: ^0.53.3 => 0.53.3

Expected Behavior

Calls to padStart should return a value according to MDN

Actual Behavior

Calls to padStart result in an error of “undefined is not a function”

Steps to Reproduce

Call padStart on a string.

const test = 'hello'
console.log(test.padStart(2, '0')) // results in 'undefined is not a function'

Reproducible Demo

https://snack.expo.io/ByAN82Itz

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
ulfgebhardtcommented, Jun 13, 2018

Bump - same Problem

Solution for now is:

import _ from "lodash";
const padded_string = _.padStart('MyString', 2, '0');
9reactions
numen31337commented, Jul 12, 2018

Can reproduce with “0.56”. For some reason only on the Android without attached debugger.

Read more comments on GitHub >

github_iconTop Results From Across the Web

String.prototype.padStart() - JavaScript - MDN Web Docs
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given ...
Read more >
String.prototype.padStart()
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given ...
Read more >
padStart() not working in IE11 - Stack Overflow
Edit: As mentioned in the comments, by @Plaute, the function repeat needs also to be polyfilled which can be found here: ...
Read more >
babel/preset-env
By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill proposals, you have three different options: when using ......
Read more >
#reacnative - Twitter Search / Twitter
Android padStart is undefined, likely needs to be polyfilled · Issue #18375 · facebook/react-native. When testing on Android 5.0+ (Google API 22+) I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found