jest
jest copied to clipboard
TypeError: Cannot redefine property: restore
🐛 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
I'm having a very similar error :(
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!
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.
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.
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.