【问题标题】:Browserify gives me Uncaught TypeError: Cannot read property 'prototype' of undefinedBrowserify 给了我 Uncaught TypeError: Cannot read property 'prototype' of undefined
【发布时间】:2020-05-27 19:49:18
【问题描述】:

我尝试使用命令npm i -g browserify 全局安装 npm browserify。然后我在终端 browserify app.js -o bundle.js 命令中写入,该命令创建了 bundle.js 文件,然后我转到我的 index.html 并将我的脚本更改为 <script defer src="bundle.js"/> 。我去检查确实错误 Uncaught referenceError: require is not defined 消失了,但我有这个新错误:

bundle.js:41149 Uncaught TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (bundle.js:41149)
    at Object.236../utils (bundle.js:42251)
    at o (bundle.js:1)
    at bundle.js:1
    at Object.232../application (bundle.js:40389)
    at o (bundle.js:1)
    at bundle.js:1
    at Object.230../lib/express (bundle.js:39717)
    at o (bundle.js:1)
    at bundle.js:1
(anonymous) @ bundle.js:41149
236../utils @ bundle.js:42251
o @ bundle.js:1
(anonymous) @ bundle.js:1
232../application @ bundle.js:40389
o @ bundle.js:1
(anonymous) @ bundle.js:1
230../lib/express @ bundle.js:39717
o @ bundle.js:1
(anonymous) @ bundle.js:1
(anonymous) @ bundle.js:36124
206._process @ bundle.js:36133
o @ bundle.js:1
r @ bundle.js:1
(anonymous) @ bundle.js:1

【问题讨论】:

  • 你也可以发布你的代码吗?
  • @PawanKumar 我发布了答案

标签: javascript html node.js browserify


【解决方案1】:

这是我的 app.js 文件,索引 html 中没有任何内容。而且 bundle.js 有大约 60k 行代码,我无法显示。

const express = require("express");
const app = express();

const PORT = process.env.PORT || 5500;

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

【讨论】:

  • html 只是baysic布局,什么都没有,&lt;script defer src="bundle.js"/&gt;
  • 我可以看到同样的错误。此错误是由于http 对象缺少ServerResponse 字段。
  • @PawanKumar 我该如何解决
  • 我想知道您为什么要浏览化 Web 服务器应用程序。由于安全目的,大多数功能都无法工作。在浏览器中,您无法触摸文件系统。
  • 不要使用 browserify,使用 ES6 Imports 使用 Babel 转译 ES6 导入并且没有人想运行他们的服务器代码以在浏览器上运行。您发布的代码必须在 Web 服务器上运行。但是您试图在浏览器上运行它,这将无法正常工作,甚至被认为不安全。
猜你喜欢
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 2013-01-15
  • 2019-02-12
  • 2017-08-19
  • 2021-09-20
  • 2021-06-08
相关资源
最近更新 更多