我正在尝试在我的 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/