This is my app.js file, index html has nothing in it. And bundle.js has like 60k lines of code, I can’t show it.
const express = require("express");
const app = express();
const PORT = process.env.PORT || 5500;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
I have tried installing npm browserify globally with a command npm i -g browserify
. Then I wrote in terminal browserify app.js -o bundle.js
command, which created bundle.js file, and then I went to my index.html and I changed my script to <script defer src="bundle.js"/>
. I went to check and indeed error Uncaught referenceError: require is not defined is gone, but I have this new error:
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
Can you post your code also.
I can see the same error. This error is due to absence of
May I know why do you want to browserify the Web server application. And most of the functions wont work because of security purposes. From Browser you cannot touch File system.
Don’t use browserify, Use ES6 Imports use Babel to transpile ES6 imports and no one want to run their server code to run on browser. The code you posted must be running on a Web server. But you are trying to run it on a Browser, which wont work and is not even considered safe.