NodeJS ReferenceError- ReferenceError:cors未定义[重复]

qqrboqgw  于 12个月前  发布在  Node.js
关注(0)|答案(1)|浏览(111)

此问题已在此处有答案

How to enable cors nodejs with express?(10个答案)
8天前关闭
我正在创建一个JavaScript后端,当我运行这个后端时,我得到了这个错误。

app.use(cors())
    ^

ReferenceError: cors is not defined
    at Object.<anonymous> (C:\Users\hp\Desktop\Entri\kanba\index.js:5:5)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

我从 Postman 那里发出一个获取请求。我希望从后端的React,但我得到它的错误。

4xy9mtcn

4xy9mtcn1#

您似乎没有安装名为cors的中间件。
在项目的终端中运行此命令以安装cors
npm install cors
现在您应该在应用程序中导入cors包
const cors = require('cors ')
欲了解更多信息,请查看express cors documentation
希望这有用。祝你今天愉快!

相关问题