Skip to content

Getting error require is not defined after browserify command #100

Open
@ganeshkbhat

Description

@ganeshkbhat

Getting error require is not defined

Uncaught ReferenceError: require is not defined
    at index.html:10:27
(anonymous) @ index.html:10

The command I am using is browserify index.js > browser.js

index.html

<html>
<head>
  <script src="../browser.min.js"></script>
</head>
<body>
  <div id="isbrowser"></div>
  <script>
    const { isBrowser } = require("../index.js");
    console.log(isBrowser());
  </script>
</body>
</html>

browser.min.js

!function n(o,i,u){function c(e,t){if(!i[e]){if(!o[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(f)return f(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}r=i[e]={exports:{}},o[e][0].call(r.exports,function(t){return c(o[e][1][t]||t)},r,r.exports,n,o,i,u)}return i[e].exports}for(var f="function"==typeof require&&require,t=0;t<u.length;t++)c(u[t]);return c}({1:[function(require,e,exports){!function(t){!function(){"use strict";e.exports.isBrowser=function(){return("object"!=typeof t||"function"!=typeof require)&&"function"!=typeof importScripts&&("object"==typeof window||void 0)}}.call(this)}.call(this,require("_process"))},{_process:2}],2:[function(require,t,exports){var r,n,t=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}try{r="function"==typeof setTimeout?setTimeout:o}catch(t){r=o}try{n="function"==typeof clearTimeout?clearTimeout:i}catch(t){n=i}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return(r=setTimeout)(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}var c,f=[],s=!1,l=-1;function a(){s&&c&&(s=!1,c.length?f=c.concat(f):l=-1,f.length)&&h()}function h(){if(!s){for(var t=u(a),e=(s=!0,f.length);e;){for(c=f,f=[];++l<e;)c&&c[l].run();l=-1,e=f.length}c=null,s=!1,!function(e){if(n===clearTimeout)return clearTimeout(e);if((n===i||!n)&&clearTimeout)return(n=clearTimeout)(e);try{n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function e(){}t.nextTick=function(t){var e=new Array(arguments.length-1);if(1<arguments.length)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];f.push(new p(t,e)),1!==f.length||s||u(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},t.title="browser",t.browser=!0,t.env={},t.argv=[],t.version="",t.versions={},t.on=e,t.addListener=e,t.once=e,t.off=e,t.removeListener=e,t.removeAllListeners=e,t.emit=e,t.prependListener=e,t.prependOnceListener=e,t.listeners=function(t){return[]},t.binding=function(t){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(t){throw new Error("process.chdir is not supported")},t.umask=function(){return 0}},{}]},{},[1]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions