简体   繁体   English

尝试在 create-react-app 中导入 npm 时出错

[英]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:我正在尝试在 create-react-app 应用程序中导入 got ( https://www.npmjs.com/package/got ),当我只是尝试将它导入到一个文件中时,甚至没有尝试执行任何代码应用程序无法编译,我收到以下错误:

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. PS:我使用的是最新版本的 create-react-app 和最新版本的 got。

As gots official readme page says:正如 gots 官方自述页面所说:

Human-friendly and powerful HTTP request library for Node.js Node.js 的人性化和强大的 HTTP 请求库

So it is basically only for node js in the server side and you can not use in the front end.所以基本上只针对服务端的node js,不能在前端使用。

instead, you can use a library like axios which can be used in both front end react apps or back end nodejs apps相反,您可以使用像axios这样的库,它可以在前端 React 应用程序或后端 nodejs 应用程序中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 然后尝试 create-react-app 时出错(npm ERR!cb() never call!然后尝试 create-react-app) - Error then trying create-react-app( npm ERR! cb() never called! then trying create-react-app) 使用 create-react-app 启动 npm 错误 - npm start error with create-react-app 我正在尝试使用“npx/npm create-react-app hello”命令创建一个反应应用程序并得到了整个消息 - I am trying to create a react app using the “npx/npm create-react-app hello” command and got this whole message 使用 npx create-react-app 创建应用后<myproject> ,并使用“npm start”启动应用程序我得到了下面提到的这个错误</myproject> - After creating app using npx create-react-app <myproject> , and start app by using "npm start" i got this error mentioned below 尝试将 react-select 导入使用 create-react-app 创建的项目时出错 - Error trying to import react-select to a project created with create-react-app 使用 npm create-react-app 不起作用? - using npm create-react-app is not working? 运行 npx create-react-app 时遇到错误 - Facing error while running npx create-react-app 运行 create-react-app 命令时出错 - Getting error while running create-react-app command 在 create-react-app 中有条件地导入资产 - Conditionally import assets in create-react-app 将 bootstrap 5 组件导入 create-react-app - Import bootstrap 5 component into create-react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM