javascript - 类型错误 : Cannot read properties of undefined (reading 'prototype' ) React Typescript + Express

标签 javascript reactjs typescript express

我正在尝试在我的 React-Typescript SPA 中使用 express。但它给了我错误:

    TypeError: Cannot read properties of undefined (reading 'prototype')
(anonymous function)
node_modules/express/lib/response.js:42
  39 |  * @public
  40 |  */
  41 | 
> 42 | var res = Object.create(http.ServerResponse.prototype)
  43 | 
  44 | /**
  45 |  * Module exports.
我试过添加 target: "node"给我的"node_modules/react-scripts/config/webpack.config.js"但它不会工作...
以下是我已经尝试解决的一些方法:
    import express from "express";
    app = express();
---------------
    import express from "express";
    let app: express.Application;
    app = express();
-------------

    import express from "express";
    let app: any;
    app = express();

-------------
    const express require("express");
    let app: express.Application;
    app = express();

最佳答案

您必须同时实例化 app 和 express,同时使用 const 关键字。

const express = require('express');
const app = express();
此外,在您的代码库中查找您拥有的任何位置:
import { response } from 'express';
通常这是错误地输入的,删除此行可能会解决错误

关于javascript - 类型错误 : Cannot read properties of undefined (reading 'prototype' ) React Typescript + Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69023142/

相关文章:

javascript - 如何通过 RxJs 合并或 groupBy toPromise?

javascript - 在 Silverlight 项目中调用异步 javascript 代码

javascript - Highcharts 仅在彩色区域检测 mouseOver 事件

javascript - 我如何在 ReactJS 的 ComponentDidMount 中使用 {useState}

mysql - 从React表单发布到我的后端API时出错

node.js - 将编译的 typescript 部署到 lambda 时导入模块错误

javascript - 图片点击无效

javascript - JS多种内联样式,如何设置后备?

javascript - 下一个JS : Loading Font from Database

typescript :至少需要一个参数时使用扩展运算符