这是我第一次使用 React + ExpressJs + Typescript 我在 node_modules 中收到以下错误,我不确定它来自哪里。我已经为 node 和 expressjs 安装了类型包。
TypeError: Cannot read property 'prototype' of undefined
(anonymous function)
Z:/Project/sandbox-app/node_modules/express/lib/response.js:42
39 | * @public
40 | */
41 |
> 42 | var res = Object.create(http.ServerResponse.prototype)
43 |
44 | /**
45 | * Module exports.
这是我设置 Express 服务器的代码
import express from "express"
import bodyParser from "body-parser"
const app = express()
const port = 3000
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.get("/", (request, response) => {
response.json({ info: "Node.js, Express, and Postgres API" })
})
app.listen(port, () => {
console.log(`App running on port ${port}.`)
})
完整的堆栈跟踪
TypeError: Cannot read property 'prototype' of undefined
(anonymous function)
Z:/Project/sandbox-app/node_modules/express/lib/response.js:42
39 | * @public
40 | */
41 |
> 42 | var res = Object.create(http.ServerResponse.prototype)
43 |
44 | /**
45 | * Module exports.
View compiled
./node_modules/express/lib/response.js
http://localhost:3000/static/js/0.chunk.js:81472:30
__webpack_require__
Z:/Project/sandbox-app/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
fn
Z:/Project/sandbox-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
./node_modules/express/lib/express.js
Z:/Project/sandbox-app/node_modules/express/lib/express.js:22
__webpack_require__
Z:/Project/sandbox-app/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
fn
Z:/Project/sandbox-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
./node_modules/express/index.js
Z:/Project/sandbox-app/node_modules/express/index.js:11
__webpack_require__
Z:/Project/sandbox-app/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
fn
Z:/Project/sandbox-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
▶ 2 stack frames were collapsed.
__webpack_require__
Z:/Project/sandbox-app/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
fn
Z:/Project/sandbox-app/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
1
http://localhost:3000/static/js/main.chunk.js:1384:18
__webpack_require__
Z:/Project/sandbox-app/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
checkDeferredModules
Z:/Project/sandbox-app/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 |
View compiled
Array.webpackJsonpCallback [as push]
Z:/Project/sandbox-app/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;
View compiled
(anonymous function)
http://localhost:3000/static/js/main.chunk.js:1:75