Browserify - create bundle with external module

Bruno Bruzzano

I'm really new to browserify world. I want to use this module peer-file, in order to allow the file transfer between two browsers. Reading the Usage section into readme, I note I have to include the script bundle.js in my web page. To build the bundle I need to type browserify -r ./index.js > build.js, where -r option means external require, so I can use in my main script the keyword require(), like this:

var send = require('peer-file/send')
var receive = require('peer-file/receive')

However, when I load the web page, I receive this error into the console. Uncaught Error: Cannot find module 'peer-file/send'

Any suggestion?

Dominic

If you look at the index file - https://github.com/michaelrhodes/peer-file/blob/master/index.js

It adds send and receive to the exports. So you first get a handle to that, then you can access the exports with dot notation.

var send = require('peer-file').send;
var receive = require('peer-file').receive;

Or just get it once:

var peerFile = require('peer-file');

// Later
peerFile.send..
peerFile.receive..

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

browserify - uncaught error "cannot find module" in bundle.js

From Dev

Cannot create a standalone browserify module with dollar sign

From Dev

How to create standalone browserify bundle exporting directly to window?

From Dev

Typescript: create external module from internal module

From Dev

Typescript: create external module from internal module

From Dev

Browserify bundle undefined dependency

From Dev

Karma Browserify bundle error

From Dev

Browserify bundle undefined dependency

From Dev

Browserify fails to create bundle with babelify transform (TypeError: Path must be a string.)

From Dev

How to use Gulp to create a separate vendor bundle with Browserify from Bower components

From Dev

Multiple node modules in a browserify bundle

From Dev

Browserify bundle.js demystified

From Dev

Multiple node modules in a browserify bundle

From Dev

Grunt browserify transform ReactJS then bundle

From Dev

gulp browserify + reactify not creating bundle

From Dev

List files from browserify bundle

From Dev

Browserify "module is not defined"

From Dev

Ignore module with browserify in gulp

From Dev

AngularJS, Browserify and module loading

From Dev

Browserify requires vendor module built with Browserify

From Dev

Browserify requires vendor module built with Browserify

From Dev

Make browserify modules external with Gulp

From Dev

Make browserify modules external with Gulp

From Dev

How to use browserify to bundle a backbone app?

From Dev

Where to put 'use strict' in Browserify bundle

From Dev

browserify bundle electron app main process file

From Dev

Making Browserify bundle play nice with ReactDevTools

From Dev

How does the bundle order work in browserify?

From Dev

gulp browserify bundle time takes too long

Related Related

  1. 1

    browserify - uncaught error "cannot find module" in bundle.js

  2. 2

    Cannot create a standalone browserify module with dollar sign

  3. 3

    How to create standalone browserify bundle exporting directly to window?

  4. 4

    Typescript: create external module from internal module

  5. 5

    Typescript: create external module from internal module

  6. 6

    Browserify bundle undefined dependency

  7. 7

    Karma Browserify bundle error

  8. 8

    Browserify bundle undefined dependency

  9. 9

    Browserify fails to create bundle with babelify transform (TypeError: Path must be a string.)

  10. 10

    How to use Gulp to create a separate vendor bundle with Browserify from Bower components

  11. 11

    Multiple node modules in a browserify bundle

  12. 12

    Browserify bundle.js demystified

  13. 13

    Multiple node modules in a browserify bundle

  14. 14

    Grunt browserify transform ReactJS then bundle

  15. 15

    gulp browserify + reactify not creating bundle

  16. 16

    List files from browserify bundle

  17. 17

    Browserify "module is not defined"

  18. 18

    Ignore module with browserify in gulp

  19. 19

    AngularJS, Browserify and module loading

  20. 20

    Browserify requires vendor module built with Browserify

  21. 21

    Browserify requires vendor module built with Browserify

  22. 22

    Make browserify modules external with Gulp

  23. 23

    Make browserify modules external with Gulp

  24. 24

    How to use browserify to bundle a backbone app?

  25. 25

    Where to put 'use strict' in Browserify bundle

  26. 26

    browserify bundle electron app main process file

  27. 27

    Making Browserify bundle play nice with ReactDevTools

  28. 28

    How does the bundle order work in browserify?

  29. 29

    gulp browserify bundle time takes too long

HotTag

Archive