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.

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

See original GitHub issue

Hi!

I installed the package use-query-params: 1.1.7 but I’m getting this error When I used setQuery In react with ts, any sugestion?

image

App.tsx

import { BrowserRouter, Route } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';

const App = (): React.ReactElement => {
  return (
    <BrowserRouter>
      <QueryParamProvider ReactRouterRoute={Route}>
        ...
      </QueryParamProvider>
    </BrowserRouter>
  );
})

index.tsx

import { useQueryParams, StringParam } from 'use-query-params';

const Test = (): React.ReactElement => {
  const [query, setQuery] = useQueryParams({
    foo: StringParam,
  });
  const { foo } = query;

  return (
    <button onClick={() => setQuery({ foo: 'test!' })}>Test</button>
  )
};

I used

"use-query-params": "1.1.7",
"query-string": "6.13.2",

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
bracocommented, Mar 2, 2021

Getting this issue in ^1.2.0 @pbeshai

Problem only appears in productions builds in CRA

Fixed with installing query-string

1reaction
jasonkcommented, Sep 17, 2020

Is there any reason that you actually need to allow it to depend on v6? I suspect the reason you are getting the wrong one is that when you installed initially it didn’t have any query-string available, so it installed the latest v6 as that is the latest version that met the spec. When you then installed 5.1.1 it saw that 6 was already installed, so it didn’t bother to change the one that use-query-params was using, because the one it had available met the requirements.

It will probably work if you remove your node_modules directory and yarn.lock and run yarn with version 5 already specified in your package.json, because then it will do the resolving before downloading anything.

However, looking quickly through your code it doesn’t appear you are using anything from query-string that would make it important to use v6, so overall you would be much better off by just declaring your dependency on ^5.1.1 and not worrying about 6 until after IE11 is EOL.

Alternately, if you are really adamant about keeping v6 in the dependency you could leave it as a peer dependency and just add something to detect the situation and throw a more useful error message…

Something like:

const satisfies = require( 'semver/functions/satisfies' );
const want = '^5.1.1 || ^6';
const have = require( 'query-string/package.json' ).version;

if ( ! satisfies( have, want ) ) throw new Error( `Need query-string ${want}, but found ${have}` );

You could also try something like https://www.npmjs.com/package/install-peerdeps to install peer dependencies automatically, but I’ve found that often leads to even weirder problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript "Uncaught TypeError: object is not a function ...
Try to have the function body before the function call in your JavaScript file.
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
TypeError: Object(...) is not a function · Issue #14484 - GitHub
What is the current behaviour? I have created react functional component and implement state full logic using useState method but it throws an ......
Read more >
How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or...
Read more >
JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
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