【问题标题】:Reactjs - × TypeError: Cannot read property 'prototype' of undefinedReactjs - × TypeError:无法读取未定义的属性“原型”
【发布时间】:2020-02-25 13:47:48
【问题描述】:

无法读取未定义的属性“原型”。 /node_modules/express/lib/response.js:42

当我运行我的 react 应用程序和一个 express 后端时,我收到了这个错误。应用程序一直运行良好,直到错误突然出现。

  39 |  * @public
  40 |  */
  41 | 
> 42 | var res = Object.create(http.ServerResponse.prototype)
  43 | 

这是我在控制台中得到的:

    at Object.<anonymous> (response.js:42)
    at Object../node_modules/express/lib/response.js (response.js:1142)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/express/lib/express.js (express.js:22)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/express/index.js (index.js:11)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/actions/index.js (index.js:1)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/containers/HomeContainer.js (UserPosts.js:53)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/components/home/home.js (sidenav_items.js:80)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/routes.js (user_reducer.js:17)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/index.js (HomeContainer.js:42)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object.1 (BookItem.js:24)
    at __webpack_require__ (bootstrap:785)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1```

【问题讨论】:

  • 我假设你已经完成了所有基本的事情,比如重启、清除 node_modules 和重新安装等。BookItem.js 中的第 24 行是什么?
  • 它是一个渲染书籍项目的组件。它是我创建的第一批组件之一,并且一直在工作。

标签: javascript node.js reactjs express


【解决方案1】:

尝试将此添加到您的 webpack 配置中

target: 'node'

【讨论】:

    猜你喜欢
    • 2020-05-15
    • 2021-08-01
    • 1970-01-01
    • 2021-12-06
    • 2022-07-22
    • 2019-05-07
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多