Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object(...) is not a function #14484

Closed
sagar-gavhane opened this issue Dec 22, 2018 · 44 comments
Closed

TypeError: Object(...) is not a function #14484

sagar-gavhane opened this issue Dec 22, 2018 · 44 comments

Comments

@sagar-gavhane
Copy link

sagar-gavhane commented Dec 22, 2018

Do you want to request a feature or report a bug?

Bug 🐛🐛 (May be 🤔🙄)

What is the current behaviour?

I have created react functional component and implement state full logic using useState method but it throws an TypeError: Object(...) is not a function

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Installed packages

"dependencies": {
  "@reach/router": "^1.2.1",
  "formik": "^1.4.1",
  "prop-types": "^15.6.2",
  "react": "^16.7.0-alpha.2",
  "react-dom": "^16.7.0-alpha.2",
  "react-scripts": "2.1.1",
  "styled-components": "^4.1.3",
  "yup": "^0.26.6"
},

Github repository : https://github.com/sagar-gavhane/workbench-client
Website: https://wonderful-allen-a3058d.netlify.com/
Screenshot:
screenshot

@nikilok
Copy link

nikilok commented Dec 22, 2018

@sagar-gavhane you got a few glitches in your project setup.
/src/components/Input/input.js

Line 1 should be
import Input from './Input.jsx'

/src/screens/auth/Login/Login.jsx
Line 1 should be
import Input from '../../../components/Input/input.js'

and in package.json
use
"react": "next",
"react-dom": "next",

You should be good after that.

@rwieruch
Copy link

I ran into this issue as well because somehow I assumed that Hooks moved into 16.7.0-alpha.2. But I had to use next instead. Thanks @nikilok

@VdustR
Copy link

VdustR commented Dec 24, 2018

16.7.0(latest) is not with hooks yet. Use 16.7.0-alpha.2(or next) instead for now.

FYI React v16.7: No, This Is Not The One With Hooks.

@pungggi
Copy link

pungggi commented Dec 25, 2018

16.7.0(latest) is not with hooks yet. Use 16.7.0-alpha.2(or next) instead for now.

FYI React v16.7: No, This Is Not The One With Hooks.

very confusing..

@WillSquire
Copy link

Had to use next instead of 16.7.0-alpha.2 also, is this expected behaviour?

Really wanted a specific version in package.json instead of next.

@JNaeemGitonga
Copy link

JNaeemGitonga commented Dec 29, 2018

Hey guys! How are you using next to use hooks? FB says they aren't even releasing yet and that it will be a few months, read here. currently I am using 16.7.0-alpha.2 and I still get the error.

@ctur
Copy link

ctur commented Dec 30, 2018

The link you have passed already says that? @JNaeemGitonga

@JNaeemGitonga
Copy link

@ctur can tell you didn't read the question.

@EdmundsEcho
Copy link

FYI - using 16.7.0-alpha.2 should work as an entry into the package.json. However, in my experience, only when I changed the entry to next (per the advice above), did the error go away.

Note, I also deleted my yarn.lock and node_modules for good measure.

@gaearon
Copy link
Collaborator

gaearon commented Jan 9, 2019

Both 16.7.0-alpha.2 and next (which we've fixed to point to it) should work.

@gaearon gaearon closed this as completed Jan 9, 2019
@gaearon
Copy link
Collaborator

gaearon commented Mar 19, 2019

(But 16.8 is the first stable version to have Hooks)

@volkanunsal
Copy link
Contributor

I just started getting this error in production. It doesn't happen in development, though. I'm using 16.8.x. Can anyone shed light on what is actually causing it?

@gaearon
Copy link
Collaborator

gaearon commented Mar 19, 2019

This error might happen if you use old React. It's not even a React error — you're calling React.useState(), and if that doesn't exist (such as in old versions), it's like calling React.lalalala(). The function doesn't exist, so you're calling undefined() and it crashes.

It might also happen if you call a non-existent method on some other library.

@volkanunsal
Copy link
Contributor

Thanks, Dan!

@steelx
Copy link

steelx commented Apr 26, 2019

I was getting the same erorr, but then I released I was using createState instead of useState

@merveillevaneck
Copy link

Hey! came across this while having a very similar issue except ive checked all the solutions and it doesnt seem to solve the problem. I'm very new to functional paradigms and react(and even javascript), what else should i try to investigate?

I've got a lambda function as a component which has a body that starts off by generating some hooks. but it looks like the lambda isnt recognised, even though all my other components are lambdas too and they seem to work fine

@corysimmons
Copy link

Might help someone: Make sure you aren't import { Foo } from 'Foo' when you should be import Foo from 'Foo'. That is... this error is actually pretty descriptive and you can confirm it by commenting out the erroring out code, then doing something like console.log(typeof Foo) to see if it is an actual function or if it's something completely different.

@Tony1106
Copy link

I have the same error and just figure it out. The problem is when you copy the code from the demo site, this line is not correct:

import { makeStyles } from '@material-ui/core/styles';

Change to this one:

import { makeStyles } from "@material-ui/styles";

Check the docs from here

@Vijay-Barve
Copy link

try this
npm install rxjs@6.3.3 rxjs-compat@6.3.3 --save

@EdDevs2503
Copy link

Hey, your problem is complicated, but i could resolvet. You problem is React version. run this command: npm install react@next react-dom@next --save

@eebasadre20
Copy link

Hey, your problem is complicated, but i could resolvet. You problem is React version. run this command: npm install react@next react-dom@next --save

@EdDevs2503 I tried yours but it didn't work for me. I found out that when I tried to import { useRouter, matchPath } from 'next/router', the matchPath is undefined. I'm not sure what will be the equivalent of matchPath in next.

@kami23
Copy link

kami23 commented Sep 8, 2019

Hello , i have the same problem and the version of react that i am using is :
"react": "^16.9.0",
"react-dom": "^16.9.0",
How to solve this ? i tried to use the next solution and it didn't work

@kapilgorve
Copy link

@kami23 I just ran into this error. It could also be an indication that you are importing something in your component which doesn't exist.
For me it was this - import { withNavigation } from '@react-navigation/web';
This withNavigation doesn't exist inside the @react-navigation/web .

@moh-nur
Copy link

moh-nur commented Sep 17, 2019

I was getting the same error. It was due to importing useState from the wrong library. If you're using >16.8 make sure you have:

import React, { useState } from 'react';

@N-Akoma
Copy link

N-Akoma commented Sep 23, 2019

TypeError: Cannot read property 'pxToRem' of undefined
(anonymous function)
C:/Users/Young Akoma/Desktop/Anthony/page-app/src/Components/Explore.js:16
13 | width: '100%',
14 | },
15 | heading: {

16 | fontSize: theme.typography.pxToRem(15),
| ^ 17 | flexBasis: '33.33%',
18 | flexShrink: 0,
19 | },

please i really need help for this. i cant resolve it

@kevinjose1
Copy link

I got the same error, but somehow sorted it well . The issue was due to the React and React- Dom versions. I was using the older versions of React and React-dom. The issue sorted when i upgraded into latest version.
Please make sure that you update both React and React-dom at the same time.
Run the below commands in cmd to upgrade React . Open your package.json and check your current react and react-dom before updating.

npm install --save react@latest
npm install --save react-dom@latest

@jith87
Copy link

jith87 commented Oct 18, 2019

Hey, your problem is complicated, but i could resolvet. You problem is React version. run this command: npm install react@next react-dom@next --save

This fixed the issue.

@waqaramjad
Copy link

@sagar-gavhane you got a few glitches in your project setup.
/src/components/Input/input.js

Line 1 should be
import Input from './Input.jsx'

/src/screens/auth/Login/Login.jsx
Line 1 should be
import Input from '../../../components/Input/input.js'

and in package.json
use
"react": "next",
"react-dom": "next",

You should be good after that.

thanks @nikilok you resolved my issue but i want to know the logic behind that because i never used next in react version

@N-Akoma
Copy link

N-Akoma commented Nov 12, 2019 via email

@zackster
Copy link

zackster commented Dec 2, 2019

I had to upgrade react-redux, delete my node_modules, then reinstall.

@danielravina
Copy link

danielravina commented Dec 12, 2019

I was struggling with this for the past 2 hours. was a typo for me

import React, { useContex } from "react";`

... many lines below ...

const { projects } = useContex(AppContext);

😭

@wjes
Copy link

wjes commented Jan 3, 2020

My error was trying to import useQuery from react instead of @apollo/react-hooks, thanks you all!

@jeremy-hunter
Copy link

Wow - thank you - I did the same thing 🤦

@hamzahassan52
Copy link

npm install ng2-charts@2.2.0 --save work for me. fine

@mediamaker
Copy link

I was using a named export instead of default and had to remove the brackets
import { useSiteMetadata } from "../hooks/useSiteMetadata"
import useSiteMetadata from "../hooks/useSiteMetadata"

@alexotoo
Copy link

have a closer look at the name of the value passed in reference to the function. Is it the same name you typed as your prop?
Need more details on your code

@dandv
Copy link

dandv commented May 31, 2020

All these comments about how tiny typos caused all this time waste and frustration, suggest that this error could be clarified by echoing the incorrect name. @gaearon, anything that could be done in that direction, or is this a JavaScript limitation?

@atidivya
Copy link

I am still getting the error "TypeError: Object(...) is not a function" for using the useParams from react.

"react": "^16.13.1",
"react-dom": "^16.13.1",

@jyotiprakash111
Copy link

@atidivya Do you able to solve the issue or not ?

@KrunalRajkotiya
Copy link

KrunalRajkotiya commented Jul 28, 2020

I had come across the same problem and what worked for me is updating the react and react-dom to the latest version.

To update to the latest version.
npm install --save react@latest
npm install --save react-dom@latest

Now my current version of react and reat-dom is
"react": "^16.13.1"
"react-dom": "^16.13.1"

@THPubs
Copy link

THPubs commented Aug 24, 2020

I was using a named export instead of default and had to remove the brackets
import { useSiteMetadata } from "../hooks/useSiteMetadata"
import useSiteMetadata from "../hooks/useSiteMetadata"

Thanks a lot @mediamaker . This worked for my use case where I was importing a function which use React inside a NextJS project.

@lavahasif
Copy link

npm install --save react@latest
npm install --save react-dom@latest
this solved my problem .when i was using usestate and useeffect in react

@smtlab
Copy link

smtlab commented Sep 21, 2020

Just do npm audit fix =)

@facebook facebook locked as off-topic and limited conversation to collaborators Sep 21, 2020
@gaearon
Copy link
Collaborator

gaearon commented Sep 21, 2020

I'm going to lock this because the comments are either getting repetitive or include unrelated suggestions.

If you have this error, it means you're importing something that doesn't exist. It doesn't have to do with React per se.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests