SyntaxError: Unexpected token export using jest
See original GitHub issueCurrent behavior
/@react-native-community/async-storage/lib/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export default from './AsyncStorage';
SyntaxError: Unexpected token export
> 1 | import AsyncStorage from "@react-native-community/async-storage"
| ^
2 |
3 | /**
4 | * Loads a string from storage.
Repro steps
import @react-native-community/async-storage
and test with jest.
Environment
- Async Storage version: 1.2.1
- React-Native version: 0.57.7
- Platform tested: iOS / Android
- Jest version: 24.0.11
- Logs/Error that are relevant: see above
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:37 (11 by maintainers)
Top Results From Across the Web
Jest gives an error: "SyntaxError: Unexpected token export"
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >Jest SyntaxError: Unexpected token 'export' #3443 - GitHub
Our team is going to avoid upgrading until this issue is resolved. Seems very unusual to put raw ES exports in the main...
Read more >Jest SyntaxError: Unexpected token 'export'
For Webpack it is fine because it passes all the code through Babel, links all dependencies, and transpile them to vanilla js which...
Read more >jest export unexpected token - You.com | The AI Search ...
It appears to me that there is an issue in the package you're using. It's trying to use ES modules syntax (import /...
Read more >TypeScript Jest: Unexpected Token Export - Reddit
But most likely you will want to use common JS modules. Check your ts-config module settings to output to commonjs, and update your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @loic-lopez
Async Storage is not being transformed by Jest, so in your
jest.config.js
orjest
entry inpackage.json
, add:Sure @Krizzu! As you said in your comment I’ve created
__mocks__/@react-native-community/async-storage/index.js
An then in my tests I just import and mock
@react-native-community/async-storage
like this: