【发布时间】:2021-10-31 12:13:52
【问题描述】:
我正在尝试在我的 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();
【问题讨论】:
-
我认为问题在于您忘记使用 const、var 或 let 实例化
app,因为它应该可以工作。 -
@KennethLew 抱歉我复制不正确,但我使用的是 const app = express()
-
@KennethLew 我看到了那个帖子,但它对我不起作用......
-
或许可以试试
import * as express from "express"
标签: javascript reactjs typescript express