question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

external('file') breaks if browserify can't resolve 'file'.

See original GitHub issue

So, I want to provide my own versions of the core modules, not to run them in the browser, but instead to run them in a secure context.

From what I can see, I should use browserify.external(file) to tell browserify that i’m using an external module, however, this breaks if the module required is not provided by browserify-resolve.

example:

var browserify = require('browserify')
var path = require('path')

var secure = browserify(path.resolve(process.argv[2]))

var core = [
  "assert"   , "buffer_ieee754", "buffer"        , "child_process"
, "cluster"  , "console"       , "constants"     , "crypto"
, "_debugger", "dgram"         , "dns"           , "domain"
, "events"   , "freelist"      , "fs"            , "http"  
, "https"    , "_linklist"     , "module"        , "net" 
, "path"     , "punycode"      , "querystring"   , "readline"
, "repl"     , "stream"        , "string_decoder", "sys"
, "timers"   , "tls"           , "tty"           , "url"
, "util"     , "vm"            , "zlib"          , "os"
]

//don't bundle any core modules
core.forEach(function (m) {
  secure.external(m)
})


secure
  .bundle()
  .pipe(process.stdout)

I get this error:

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: module "buffer_ieee754" not found in require()
    at Browserify.require (/Users/dominictarr/c/node_modules/browserify/index.js:58:46)
    at resolve (/Users/dominictarr/c/node_modules/browserify/node_modules/browser-resolve/index.js:115:16)
    at Browserify.require (/Users/dominictarr/c/node_modules/browserify/index.js:56:5)
    at Browserify.external (/Users/dominictarr/c/node_modules/browserify/index.js:95:17)
    at /Users/dominictarr/c/securify/index.js:21:10
    at Array.forEach (native)
    at Object.<anonymous> (/Users/dominictarr/c/securify/index.js:20:6)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)

the error comes from here:

https://github.com/substack/node-browserify/blob/master/index.js#L59

which is before the bit that checks whether that file should be excluded.

https://github.com/substack/node-browserify/blob/master/index.js#L71-L73

So, it has to be able to resolve modules that I want to exclude… which seems unnecessary, especially for non-relative modules.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
deoxxacommented, Aug 16, 2013

I just ran into this problem. Now it’s fixed. Open source software is magical.

0reactions
aberniercommented, Aug 16, 2013
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to exclude library files from browserify bundle
The answer is to use browserify-shim In order to figure it out, I created a slightly more complicated scenario with a fake lib...
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
How to polyfill node core modules in webpack 5 - Alchemy
4 easy steps to fix polyfill node core modules in webpack 5 · 1. Install react-app-rewired · 2. Install missing dependencies · 3....
Read more >
Webpack or Browserify & Gulp: Which Is Better? - Toptal
This particular issue can often be addressed by bundling the files together, so you're only requesting a single bundled JS and CSS file...
Read more >
browserify-middleware - npm
Usage ; provide browserified versions of all the files in a directory · use · /js · __dirname + '/client/dir') ; provide a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found