#node.js #typescript #express
#node.js #машинопись #экспресс
Вопрос:
Это мой первый раз, когда я работаю с 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.
Вот код, в котором я настраиваю экспресс-сервер
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 resu<
View compiled
(anonymous function)
http://localhost:3000/static/js/main.chunk.js:1:75
Комментарии:
1. Я думаю, что ваш синтаксис импорта неверен. Так и должно быть
import * as express from 'express'
.2. Я так не думаю, потому что это синтаксис импорта ES6
3. Да, я искал правильный способ экспорта express. Приношу свои извинения за более ранний, вводящий в заблуждение комментарий. Можете ли вы предоставить полную трассировку стека ошибок?
4. Я только что добавил полную трассировку стека в сообщение, спасибо, что посмотрели