When i run jest test component should not have errors.
No errors
28 | if ('REALM_DISABLE_ANALYTICS' in process.env) {
29 | module.exports = function(){};
> 30 | return;
| ^
31 | }
32 |
33 | const os = require('os');
@bang88 Could you fill in the steps to reproduce this issue?
I will test it later.
@ashwinphatak The problem are still there.
Just run jest test your js files if one of them imports realm. I have update realm to 2.0.1.
@bang88 I can't reproduce the issue in a test project. Can you check if this code works for you?
Realm import in test file:
https://github.com/ashwinphatak/RealmIssue1422/blob/master/__tests__/App.js#L5
Test run:

@ashwinphatak I tested like you said. here is my tests file
import Realm from 'realm';
just one line code
errors:
$ yarn test -o
yarn run v1.2.1
$ jest -o
FAIL src/models/__tests__/index.js
● Test suite failed to run
/Users/bang/dev/apps/myapp/node_modules/realm/lib/submit-analytics.js: 'return' outside of function (30:4)
28 | if ('REALM_DISABLE_ANALYTICS' in process.env) {
29 | module.exports = function(){};
> 30 | return;
| ^
31 | }
32 |
33 | const os = require('os');
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.08s
Ran all test suites related to changed files.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Unfortunately, I can't reproduce it when running yarn test either. Could you upload a minimal RN project which reproduces the issue?
I can't reproduce it using your repo. Maybe something wrong with my code. I will check it later. 😢
@bang88 by the end, have you figured it out? I have the same problem
@EJohnF Not yet. 😢
@bang88 try to modify your package.json:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(realm)/"
]
}
it helps me
@EJohnF wow and thank you very much, ignoring "node_modules/(realm)/"helped me resolve _return outside of function_ error!
Sadly I came across the same problem. Adding realm to the transformIgnorePatterns did not worked for me.
FAIL tests/App.test.js
● Test suite failed to run
/Users/u/Development/project/app/node_modules/realm/lib/submit-analytics.js: 'return' outside of function (30:4)
28 | if ('REALM_DISABLE_ANALYTICS' in process.env) {
29 | module.exports = function(){};
> 30 | return;
| ^
31 | }
32 |
33 | const os = require('os');
Is there another solution?
What could I have forgotten?
I also just ran into the _'return' outside of function_ error, ironically _after_ I added realm to transformIgnorePatterns while trying to resolve another error (SyntaxError: Unexpected token import).
FAIL src/store/data/queries.spec.js
● Test suite failed to run
/Users/me/project/node_modules/realm/lib/submit-analytics.js: 'return' outside of function (30:4)
28 | if ('REALM_DISABLE_ANALYTICS' in process.env) {
29 | module.exports = function(){};
> 30 | return;
| ^
31 | }
32 |
33 | const os = require('os');
And from my jest config:
"transformIgnorePatterns": [
"node_modules/(?!(react-native|redux-persist|glamorous-native|realm)/)"
],
Did you resolve this @donni106?
I was able to resolve the issue with the following in .babelrc:
"parserOpts": {
"allowReturnOutsideFunction": true,
},
Most helpful comment
@bang88 try to modify your package.json:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(realm)/"
]
}
it helps me