question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncStorage.js: Unexpected token, expected ";" (40:5)

See original GitHub issue

Hi, I got this error when I am trying to compile:

 Starting compilation in watch mode...
 Found 0 errors. Watching for file changes.
 Starting the development server...
 Failed to compile.
/Users/myuser/Developer/tindev-monorepo/node_modules/@react-native-community/async-storage/lib/AsyncStorage.js
SyntaxError: /Users/myuser/Developer/tindev-monorepo/node_modules/@react-native-community/async-storage/lib/AsyncStorage.js: Unexpected token, expected ";" (40:5)

  38 | }
  39 | 
> 40 | type ReadOnlyArrayString = $ReadOnlyArray<string>;
     |      ^
  41 | 
  42 | type MultiGetCallbackFunction = (
  43 |   errors: ?$ReadOnlyArray<Error>,

Versions:

@react-native-community/async-storage”: “^1.6.1”, “react-native-web”: “0.11.1”, “react-native”: “^0.60.5”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AnyBytecommented, Sep 15, 2019

Getting the same error with this code

const storage = Platform.select({
  web: () => require("localforage"),
  android: () => require("@react-native-community/async-storage").default
})();

when compiling for the WEB. I don’t understand why bundler still tries to import it when it clearly shouldn’t. I tried resetting cache, yarn and deleting node_modules folders with no luck. And the only way Im able to make it work is explicitly writing const storage = require("localforage") and removing require("@react-native-community/async-storage") line completely. This is so strange.

Update: resolved my issue by adding path.resolve('../../node_modules/@react-native-community/async-storage') line into babelInclude([]) section in packages/web/config-overrides.js file.

0reactions
tido64commented, Nov 22, 2022

@muazazhar: This issue is probably no longer relevant to the error you’re seeing. We’ve sinced migrated AsyncStorage to TypeScript. If you’re still seeing Flow issues, it’s not because of AsyncStorage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON.parse(object) when getting from asyncStorage throws ...
JSON.parse(object) when getting from asyncStorage throws error: Unexpected token o in JSON at position 1 ; JSON.stringyfy , is that a typo or...
Read more >
AsyncStorage.js: Unexpected token, expected ";" : r/reactnative
No, async storage uses sqlite, mmkv reads and writes data to text file. You can use 2 of them same time. If you...
Read more >
AsyncStorage · React Native
The AsyncStorage JavaScript code is a facade that provides a clear JavaScript API, real Error objects, and non-multi functions.
Read more >
jest SyntaxError: Unexpected token Code Example
Uncaught (in promise) DOMException: Failed to load because no supported source was found. ... This can also happen when the JS bundle is...
Read more >
How To Use React Native AsyncStorage - JScrambler Blog
This reading and writing of data are going to be done with the help of AsyncStorage API functions. Open the App.js file and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found