-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Error in Async Example: ReferenceError: regeneratorRuntime is not defined #3126
Comments
This doesn't repro locally on our CI or locally. Maybe there is something wrong with your version of npm? |
Thanks Chris. This issue can be reproduced from docker container running node:latest from following repository: Below are the steps which lead to an error: # from local machine (also tested in vagrant 1.9.2 running ubuntu/trusty64)
docker pull node:latest
docker run --rm -it node bash
# from inside the container (docker version 17.03.0-ce, node version 7.7.2)
git clone https://github.com/facebook/jest /jest
cd /jest
# as per instructions from https://github.com/facebook/jest/tree/master/examples
npm install
cd examples/async
npm install
npm test Am I correct in the way I execute this example? Edit: I'm going to assume that jest in master is actually compatible with the former module, but the example doesn't use master code and instead pulls the latest release which may still require babel-polyfill. |
I'm experiencing the same issue with Travis CI: https://travis-ci.org/okonet/lint-staged/jobs/212179781 Tests running okay locally but not on CI |
I just bumped into this issue! @mpontus @okonet you can use Jest used to autoinclude The problem is that we eradicated |
@thymikee How can I use jest.config.js
jest.transform.js
|
Sorry to wake up an old issue: I'm running into the same issue with Jest 20.0.4, and can't really suss out the take-away of these comments. From what I can see:
|
I was facing the same issue, importing the ...
"setupFiles": [
"<rootDir>/jest.init.js"
],
... /// jest.init.js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'babel-polyfill'; |
Sorry for the bump! But I wanted to share 😄 . Adding this in my general plugins works for me:
I don't know if this is the best way of handling it, though. |
This worked for me to fix "ReferenceError: regeneratorRuntime is not defined" in Jest:
Then in .babelrc (besides other options): {
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
}
}
} |
To avoid errors with using `async` in the jest tests on v24, this fix was required: jestjs/jest#3126 (comment)
I tried importing the polyfill in My
Hence I had to import the polyfill in
Except for the polyfill import line, the 3 other lines were already in the file when I opened it. Importing the polyfill in |
Adding targets node current worked for me to fix "ReferenceError: regeneratorRuntime is not defined" in Jest:
|
This won't actually help babelyfing, my code won't be compiled with the target node current. It will look exactly the same (ES6). Tests would be running, great, but no compiled code :P |
Here's a snippit of my package.json, this works for me now. "babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-react"
],
"plugins": [
"component-identification",
"@babel/plugin-proposal-class-properties",
[
"module-resolver",
{
"root": [
"./src"
]
}
]
]
}, |
For me it was not enough to have preset-env targets specified in common config. {
'presets': [
[
'@babel/preset-env',
{
'targets': {
'chrome': 61,
'node': 8,
'electron': '2.0.9'
},
}
],
'@babel/typescript',
'@babel/preset-react'
],
'env': {
'test': {
'presets': [
[
'@babel/preset-env',
{
'targets': {
'node': 8, // <- ADDED
},
}
],
'@babel/typescript',
]
}
}
} |
The only thing I had to do is to define the target in babel as mentioned by @AoDev. No additional targets elsewhere. |
To import and define regenerator-runtime globally, you do:
For those that just want to add the required thing, and not mess around with adding all babel polyfills for jest. |
This was mentioned in the blog post introducing Jest 24, if people missed it: https://jestjs.io/blog/2019/01/25/jest-24-refreshing-polished-typescript-friendly#breaking-changes. You need to configure babel properly, no need to change any code. See this comment from the PR: #7595 (comment) |
@ghengeveld This is work for me, Thank you |
What solved it for me, was to not just add the regenerator, but also the runtime to my config: 'globals': {
'vue-jest': {
'babelConfig': {
'plugins': [
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-runtime',
],
'presets': [['@babel/preset-env', { 'modules': false }]],
'env': {
'test': {
'presets': [
['@babel/preset-env', { 'targets': { 'node': 'current' } }],
],
},
},
},
},
}, |
@here none of the attempts here have worked out for me , I still seem to be getting Test suite failed to run
This my my package.json .babelrc |
* First commit * Simple version of snackbar * Add support for async/await in tests https://github.com/facebook/jest/issues/3126\#issuecomment-483320742 * Tests for snackbar * Add better button labels, add knobs for storybook * Add version with Moss green 34 as action button color * Remove button color because of lack of contrast on hover * Wider query for 'larger screen' -> 1200px. Swap center and left, had this mixed up * Add lighter button color example
Also added babel-polyfill to setup, which is no longer automatically included with jest. See jestjs/jest#3126 (comment)
Encountered same issue. Fresh upd. In my case, I had babel.config.js already but was missing |
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. |
I'm getting following error when trying to run an example from this directory:
https://github.com/facebook/jest/tree/master/examples/async
Same issue can be reproduced using node 6.10 and node 7.7.4:
The text was updated successfully, but these errors were encountered: