external('file') breaks if browserify can't resolve 'file'.
See original GitHub issueSo, 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:
- Created 10 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just ran into this problem. Now it’s fixed. Open source software is magical.
thx @jmreidy