Search code examples
javascriptnpmcreate-react-appnode.js-got

Error while trying to import npm got in create-react-app


I am trying to import got (https://www.npmjs.com/package/got) in a create-react-app application and when I am just trying to import it in one file, without even trying to execute any code the app fails to compile and I get the following error:

util.js:601 Uncaught TypeError: The "original" argument must be of type Function
    at Object.promisify (util.js:601)
    at Object.<anonymous> (get-body-size.js:7)
    at Object../node_modules/got/dist/source/utils/get-body-size.js (get-body-size.js:30)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.<anonymous> (normalize-arguments.js:15)
    at Object../node_modules/got/dist/source/normalize-arguments.js (normalize-arguments.js:441)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.<anonymous> (as-promise.js:8)
    at Object../node_modules/got/dist/source/as-promise.js (as-promise.js:152)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/got/dist/source/create.js (create.js:4)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/got/dist/source/index.js (index.js:7)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../src/utils/ph_loader.js (ph_loader.js:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/components/Video.jsx (Searchbar.jsx:3)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/App.js (src sync:9)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?f3f6:45)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (ph_loader.js:21)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

PS: I am using the latest version of create-react-app and the latest version of got.


Solution

  • As gots official readme page says:

    Human-friendly and powerful HTTP request library for Node.js

    So it is basically only for node js in the server side and you can not use in the front end.

    instead, you can use a library like axios which can be used in both front end react apps or back end nodejs apps