繁体   English   中英

TypeError:无法读取未定义的属性(读取“原型”)React Typescript + Express

[英]TypeError: Cannot read properties of undefined (reading 'prototype') React 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';

通常这是错误输入,删除此行可能会解决错误

遇到同样的问题

它是根据进口的

import e from "express";

不确定任何随机 IntelliSense 扩展或 GH 副驾驶自动完成的原因

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM