jest icon indicating copy to clipboard operation
jest copied to clipboard

TypeError: Cannot redefine property: restore

Open guilhermetelles opened this issue 4 years ago • 2 comments

🐛 Bug Report

We use a monorepo, and most of the time when we try to test a file that imports another module from the monorepo, an error occurs. One of the most common is:

    TypeError: Cannot redefine property: restore
        at Function.defineProperty (<anonymous>)

      1 | export * from "./src/shop";
    > 2 | export * from "./src/payment";
        | ^

We've even tried jest without babel, since now ES modules are partially supported (https://github.com/facebook/jest/issues/9430). However, we had some problems, specifically https://github.com/facebook/jest/issues/10025

In this small repo, when I removed the rewire-exports babel plugin from the config file it seemed to work (even though I didn't tried to rewire any module), but in my official repo I received the following error:

TypeError: content.match is not a function
    at separateMessageFromStack (/home/telles/workspace/yggdrasil/node_modules/.pnpm/[email protected]/node_modules/jest-message-util/build/index.js:414:32)
    at formatExecError (/home/telles/workspace/yggdrasil/node_modules/.pnpm/[email protected]/node_modules/jest-message-util/build/index.js:180:21)
    at onFailure (/home/telles/workspace/yggdrasil/node_modules/.pnpm/@jest/[email protected]/node_modules/@jest/core/build/TestScheduler.js:206:74)
    at /home/telles/workspace/yggdrasil/node_modules/.pnpm/[email protected]/node_modules/jest-runner/build/index.js:112:27

Link to repl or repo (highly encouraged)

https://github.com/guilhermetelles/test-error-repo

To Reproduce

cd reaction-shops-plugin-api/
npm i
jest

Expected behavior

Jest with babel should import modules correctly

envinfo

System: OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa) CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz Binaries: Node: 13.14.0 - ~/.nvm/versions/node/v13.14.0/bin/node npm: 6.14.4 - ~/.nvm/versions/node/v13.14.0/bin/npm npmPackages: jest: ^25.1.0 => 25.5.4


guilhermetelles avatar Oct 09 '20 17:10 guilhermetelles

I'm having a very similar error :(

Screen Shot 2021-03-23 at 14 53 31

luiznasciment0 avatar Mar 23 '21 17:03 luiznasciment0

There's a quite similar exception when using babel-plugin-rewire, see https://github.com/speedskater/babel-plugin-rewire/issues/144. The OP seems to use a different plugin though, babel-plugin-rewire-exports. Out of curiosity, I tried swapping babel-plugin-rewire for babel-plugin-rewire-exports in my repro without changing anything else and got the exception as well. It looks like both plugins have the same bug!

eventlistener avatar Aug 04 '22 18:08 eventlistener

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 04 '23 19:08 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Sep 03 '23 20:09 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Oct 04 '23 00:10 github-actions[bot]