jest: @jest-environment node not working in v22
Seeing this error message:
TypeError: environment.setup is not a function
at node_modules/jest-runner/build/run_test.js:112:23
When using this syntax at the top of the test file (worked in v21):
/**
* @jest-environment node
*/
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 26 (9 by maintainers)
Commits related to this issue
- upgrade ts-jest https://github.com/ant-design/ant-design/pull/9527#issuecomment-370654028 https://github.com/facebook/jest/issues/5119 — committed to ant-design/antd-tools by afc163 6 years ago
- Upgrade jest - this avoids the following documented error https://github.com/facebook/jest/issues/5119 - this also removes `node_modules/.bin` which is automatically added to the path — committed to carpeliam/boston2delhi by carpeliam 6 years ago
- Fix jest-environment issue by removing jest package Jest is included in react-scripts. This was causing a problem because that version was different than the one installed at the top level of package... — committed to elsaywang/destination by deleted user 6 years ago
If you have both
react-scripts
andjest
in yourpackage.json
, deletejest
from it. Then deletepackage-lock.json
,yarn.lock
andnode_modules
. Then runnpm install
(oryarn
if you use it).@dougbacelar
It is not supported to update Jest manually in a CRA project. If you have both
jest
andreact-scripts
in yourpackage.json
you should delete anything withjest
inpackage.json
and wait until we updatereact-scripts
ourselves πHad the same problem and solved it by downgrading
Jest
on mypackage.json
from"jest": "22.0.4",
to"jest": "20.0.4",
I just changed the version and ran
yarn install
Before the fix my output for the command
npm ls jest-environment-node
was:After the fix:
Would someone please explain the fix for this? I was not clear after reading through this problem.
I setup my app with
When I run
npm test
I get errors.First it was
jest-cli
that I needed. Once I installedjest-cli
I started seeing this error,TypeError: environment.setup is not a function
When I run,
npm ls jest-environment-node
This is my .babelrc
This is my package.json
If you use create-react-app you canβt upgrade jest without them doing it as well
have you upgraded the dependency on the env as well?
npm ls jest-environment-node
--use-npm
@gaearon You are the real MVP, thanks! I accidentally installed those packages during setup and this saved me.
I update jest-preset-angular@latest (which is version 5.0.0) and this solved the problem for me.
@gaearon, that didnβt fix what Iβm running into with a new CRA app (TypeError: environment.setup is not a function)
It turns out that
--env=jsdom
was my problemβ¦back to bliss.It seems like at least in part the problem is on the Jest side. I created an issue: https://github.com/facebook/jest/issues/5294.
If you are trying @gaearonβs fix and have jest-cli then delete that as well.
I think the same checks should be done for CRNA as well.
Weβll start doing preflight checks in future CRA versions to fail fast with clear instructions when this happens. https://github.com/facebookincubator/create-react-app/pull/3771