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.

[ios] (0,w.useState) is not a function. error on archive(release) version

See original GitHub issue

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

The error code below is from XCode. This error happenes only on archived(release) version of the app. In debug mode, it’s all good.

*** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: TypeError: (0,w.useState) is not a function. (In '(0,w.useState)(!1)', '(0,w.useState)' is undefined)

This error is located at:
    in j
    in RCTView
    in View
    in f
    in n
    in Unknown
    in Unknown
    in Unknown
    in Unknown
    in RCTView
    in View
    in H
    in RCTView
    in View
    in RCTView
    in View
    in Unknown
    in RCTView
    in View
    in f
    in Unknown
    in D
    in Unknown
    in te
    in Unknown
    in Unknown
    in Unknown
    in Unknown
    in RCTView
    in View
    in RCTView
    in View
    in RCTView
    in View
    in ForwardRef
    in RCTView
    in View
    in k
    in ForwardRef
    in PanGestureHandler
    in Unknown
    in RCTView
    in View
    in k
    in ForwardRef
    in RCTView
    in View
    in G
    in Unknown
    in RCTView
    in View
    in Unknown
    in RCTView
    in View
    in Unknown
    in O
    in h
    in Unknown
    in RCTView
    in View
    in G
    in Unknown
    in re
    in Unknown
    in ForwardRef
    in Unknown
    in ForwardRef
    in RNCSafeAreaProvider
    in Unknown
    in Unknown
    in _
    in RCTView
    in View
    in Unknown
    in y
    in Root
    in RCTView
    in View
    in C', reason: 'Unhandled JS Exception: TypeError: (0,w.useState) is not a function. (In '(0,w.useState)(!1)', '(0,w.useState)' is undefined)

This error is located at:
    in j
    in RCTVie..., stack:
j@1359:1779
fr@98:38814
Ci@98:80362
Cl@98:74733
Rl@98:74658
Pl@98:74425
Tl@98:71558
Tl@(null):(null)
<unknown>@98:23572
<unknown>@203:3882
an@98:23519
ln@98:23454
xe@98:89263
Se@98:12419
Re@98:12808
receiveEvent@98:13217
value@27:3350
<unknown>@27:747
value@27:2610
value@27:719
value@(null):(null)
'

React Native version:

Run react-native info in your terminal and copy the results here.

System:
    OS: macOS 11.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 45.89 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.4.1 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 26, 28, 29
      Build Tools: 26.0.2, 28.0.3, 29.0.0, 29.0.2, 29.0.3
      System Images: android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.3/12C33 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_201 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.4 => 0.63.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Build an app in release mode or archive the app on XCode
  2. The error above happens

Expected Results

Describe what you expected to happen. It runs without any errors just like the app of debug mode.

Snack, code example, screenshot, or link to a repository:

Please provide a Snack (https://snack.expo.io/), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem. You may provide a screenshot of the application if you think it is relevant to your bug report. Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

69reactions
niklasgycommented, Feb 16, 2021

Hi @giftset, I had a similar problem. You probably used auto-import and imported useState from the wrong path.

You have to use

import { useState } from "react";

instead of

import { useState } from "react/cjs/react.development";

0reactions
walidmokhtaricommented, Feb 18, 2022

Hi @giftset, I had a similar problem. You probably used auto-import and imported useState from the wrong path.

You have to use

import { useState } from "react";

instead of

import { useState } from "react/cjs/react.development";

Thank you so mush, I wasted a lot time on this problem, your comment helped me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError dispatcher.useState is not a function when using ...
json , but I'm getting an error: TypeError: dispatcher. useState is not a function 2 | import ReactDOM from "react-dom"; 3 | 4...
Read more >
The noob's guide to useState - LogRocket Blog
First of all, mutating state is a big no-no in the React ecosystem because of the fact that it heavily practices the concept...
Read more >
Steps to Solve Changes Not Reflecting When useState Set ...
Methods to solve the error when the useState set method is not reflecting an immediate change: · Using the “useEffect” hook: · Try...
Read more >
Importing useState - not available for all projects? - React.js
I was able to change the presentational component, but the container would not function when I converted this.setState to a useState method.
Read more >
How To Fix The React Hook is Called in Function Error
Released with version 16.8 in 2019, React hooks allow React ... you cannot use useState in a component that is not a function...
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