Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded #1237

Closed
leethree opened this issue Apr 12, 2023 · 6 comments
Closed

RangeError: Maximum call stack size exceeded #1237

leethree opened this issue Apr 12, 2023 · 6 comments

Comments

@leethree
Copy link

In React Native, we use 'core-js/stable/url' to polyfill the URL object. but since ~3.25 we are having this issue with cyclical dependency:

simulator_screenshot_7E7DD935-0868-4AE1-BB72-DACF87C74635

It looks like the following to modules are calling each other:

core-js/internals/make-built-in.js:

Function.prototype.toString = makeBuiltIn(function toString() {
  return isCallable(this) && getInternalState(this).source || inspectSource(this);
}, 'toString');

It's using inspectSource.

core-js/internals/inspect-source.js:

var functionToString = uncurryThis(Function.toString);

// this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
if (!isCallable(store.inspectSource)) {
  store.inspectSource = function (it) {
    return functionToString(it);
  };
}

And it's using Function.toString which is overridden by make-built-in.js, which causes the infinite call loop.

This issue is probably caused by import order. The temporary workaround is to import /inspect-source.js before importing the polyfill. But we still believe it would be great to figure out how to resolve this properly.

@zloirock
Copy link
Owner

Could you add a reproducible example? It looks like incorrect core-js usage / transpiler settings.

@zloirock
Copy link
Owner

zloirock commented Apr 24, 2023

Closed as can't reproduce. Please, provide a reproducible example and I'll try to help you.

@Reeywhaar
Copy link

Indeed patched toString calls inspectSource and inspectSource calls toString

@zloirock
Copy link
Owner

zloirock commented Jul 6, 2023

@Reeywhaar inspectSource calls cached toString.

@Reeywhaar
Copy link

@zloirock thank you for enlightenment!

So, I've fixed my problem by adding the inlineRequires: false to my metro.config.js. This comment helped.

const config = {
  transformer: {
    getTransformOptions: async () => {
      return {
        transform: {
          inlineRequires: false,
        },
      }
    },
  },
}

It has nothing to do with core-js.

@Titozzz
Copy link

Titozzz commented Sep 22, 2023

if you don't want to set all to false, you can do this

 getTransformOptions: () => ({
        transform: {
          experimentalImportSupport: true,
          inlineRequires: true,
          // Fix for core-js cyclic dependency that lead to require stack exceeded error
          nonInlinedRequires: ['../internals/inspect-source'],
        },
      }),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants