Loading Chunk Failed Error

Michael Minchang Kim·2021년 6월 1일
0
post-custom-banner

How to prevent your Loading chunk failed errors
medium link

recursive code to recall till attempsleft is 0

export default function componentLoader(lazyComponent, attemptsLeft) {
  return new Promise((resolve, reject) => {
    lazyComponent()
      .then(resolve)
      .catch((error) => {
        // let us retry after 1500 ms
        setTimeout(() => {
          if (attemptsLeft === 1) {
            reject(error);
            return;
          }
          componentLoader(lazyComponent, attemptsLeft - 1).then(resolve, reject);
        }, 1500);
      });
  });
}
profile
Soon to be the world's Best programmer ;)
post-custom-banner

0개의 댓글