mst-async-storage icon indicating copy to clipboard operation
mst-async-storage copied to clipboard

AsyncStorage.setItem is undefined

Open danstepanov opened this issue 3 years ago • 0 comments
trafficstars

Expected Behavior

Running this example, should allow you to toggle the value of spiders without any issues.

Actual Behavior

When running this example, clicking the "Toggle Spiders" button triggers a yellow box warning which suggests that AsyncStorage.setItem is undefined. Within the mst-async-storage library, persist.ts is the only place in which AsyncStorage.setItem is called, outside of with-async-storage.test.ts. The example does seem to work despite this yellow box warning. This PR suggests that this has been an issue for a while, however the PR is out-of-date.

Async Storage seems to be utilized properly, via the documentation. It was installed via expo install @react-native-async-storage/async-storage.

IMG_3135

Steps to Recreate

  1. Clone the example
  2. Run the example via yarn start, open in Expo Go
  3. Click "Toggle Spiders"

Additional Notes

When running yarn, the following is the output which seems like it might be relevant.

➜  mst-async-storage-test git:(@danstepanov/[email protected]) ✗ yarn
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > @react-native-async-storage/[email protected]" has unmet peer dependency "react-native@^0.0.0-0 || 0.60 - 0.68 || 1000.0.0".
warning " > [email protected]" has unmet peer dependency "@types/node@*".
warning Workspaces can only be enabled in private projects.
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
$ yarn compile && yarn build
yarn run v1.22.19
$ yarn tsc
$ /Users/danielstepanov/Library/Caches/Yarn/v6/.tmp/a56f80e44216870cc6b0fbe19fa28c43.22a6fe49bc0787e82d69f0ff070ea7192a9fb526.prepare/node_modules/.bin/tsc
✨  Done in 1.64s.
yarn run v1.22.19
$ BABEL_ENV=production rollup -c rollup.config.ts

build/es/mst-async-storage.js → dist/mst-async-storage.umd.js, dist/mst-async-storage.es5.js...
┌────────────────────────────────────────────────┐
│                                                │
│   Destination: dist/mst-async-storage.umd.js   │
│   Bundle Size:  10.75 KB                       │
│   Minified Size:  4.54 KB                      │
│   Gzipped Size:  1.53 KB                       │
│                                                │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│                                                │
│   Destination: dist/mst-async-storage.es5.js   │
│   Bundle Size:  9.34 KB                        │
│   Minified Size:  4.38 KB                      │
│   Gzipped Size:  1.44 KB                       │
│                                                │
└────────────────────────────────────────────────┘
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
build/es/with-async-storage.js
1: var __assign = (this && this.__assign) || function () {
                   ^
2:     __assign = Object.assign || function(t) {
3:         for (var s, i = 1, n = arguments.length; i < n; i++) {
...and 3 other occurrences
build/es/persist.js
1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {
...and 3 other occurrences
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
mobx-state-tree (guessing 'mobxStateTree')
@react-native-async-storage/async-storage (guessing 'AsyncStorage')
created dist/mst-async-storage.umd.js, dist/mst-async-storage.es5.js in 247ms
✨  Done in 0.66s.
[3/4] 🔗  Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "[email protected] || 3.x".
warning "react-native > react-native-codegen > [email protected]" has unmet peer dependency "@babel/preset-env@^7.1.6".
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
✨  Done in 11.75s.

danstepanov avatar Jun 02 '22 23:06 danstepanov