title: React Native run error: XXX could not be cloned
body: <p>I don't know how to better describe it. I was working on react-native project, something happened and I can't run it anymore for some reason. I'm getting weird messages like some function could not be cloned.</p>
  <pre><code>error: src/requests/TimeoutRequest.ts: function (path) {
            return fn.call(state, path, state);
          } could not be cloned.
  </code></pre>
  <p>or:</p>
  <pre><code>error: src/sensors/GPS.ts: Program(path) {
        importAll = path.scope.generateUid(&quot;$$_IMPORT_ALL&quot;);
        importDefault = path.scope.gen...&lt;omitted&gt;... } could not be cloned.
  </code></pre>
  <p>All the versions:</p>
  <p><code>npm version: 7.10.0</code></p>
  <pre><code>&quot;react&quot;: &quot;^16.11.0&quot;,
  &quot;react-native&quot;: &quot;^0.62.2&quot;,
  
  dev:
  &quot;@babel/core&quot;: &quot;^7.13.15&quot;,
  &quot;@babel/runtime&quot;: &quot;^7.13.10&quot;,
  &quot;babel-jest&quot;: &quot;^24.9.0&quot;,
  &quot;babel-plugin-root-import&quot;: &quot;^6.6.0&quot;,
  &quot;metro-react-native-babel-preset&quot;: &quot;^0.57.0&quot;,
  &quot;react-test-renderer&quot;: &quot;16.9.0&quot;
  </code></pre>
  <p>If I comment out this function. I get error in another one, and so on.
  What happened in between:
  I updated npm version. Then I had some issues with downloading some libraries, and I had to <code>rm -rf node_modules &amp;&amp; npm install</code>.</p>
  <p>What I tried:</p>
  <p>Googling, in general. Could not find any solution that would work. Found out it's possibly babel issue, but it's maybe completely wrong, I have no idea</p>
  <p><code>npm start --reset-cache</code></p>
  <p>deleting cache folders, watchman stuff, and so on</p>
  <p><code>npm install --legacy-peer-deps</code></p>
  <p>clone project and do everything in another folder</p>
  <p>restoring or deleting package-lock.json and yarn.lock. Installing with or without them</p>
  <p>tried updating babel versions</p>
  <p>running both android and ios with the same result</p>
  <p>running debug or release versions, building the release also fails with the same error.</p>
  <p>Nothing helps.</p>
  <p>Surprisngly, it was all working fine before, these functions it's made about were included in the previous release with no issue. Probably some libraries versions are messed up. I had them, but after <code>rm -rf node_modules</code> I don't anymore. Possibly it's babel issue. But I don't really know, I've read about it.</p>
  <p>Just in case, example the function that 'could not be cloned'. I don't even clone objects in there.</p>
  <pre><code>export async function TimeoutRequest(
      req: any,
      timeout: number = 5000,
  ): Promise&lt;Response&gt; {
      const timeoutId = setTimeout(() =&gt; controller.abort(), timeout)
      const controller = new AbortController()
  
      req.signal = controller.signal
      return new Promise((resolve, reject) =&gt; {
          fetch(req)
              .then(res =&gt; {
                  clearTimeout(timeoutId)
                  resolve(res)
              })
              .catch(err =&gt; {
                  clearTimeout(timeoutId)
                  reject(err)
              })
      })
  }
  </code></pre>
  <p>Also, added stack trace when error happens:</p>
  <pre><code>at Object.serialize (v8.js:267:7)
      at _default (node_modules/@babel/core/lib/transformation/util/clone-deep.js:16:30)
      at normalizeFile (node_modules/@babel/core/lib/transformation/normalize-file.js:52:36)
      at normalizeFile.next (&lt;anonymous&gt;)
      at run (node_modules/@babel/core/lib/transformation/index.js:31:50)
      at run.next (&lt;anonymous&gt;)
      at node_modules/@babel/core/lib/transform-ast.js:20:41
      at Generator.next (&lt;anonymous&gt;)
      at evaluateSync (node_modules/gensync/index.js:251:28)
  </code></pre>
  <p>I would really appreciate an feedback, I'm stuck at this point.</p>